I'm working with a classic ASP VBScript page that queries post town details for a UK postcode given as a parameter, and I've been adding some additional code to catch error situations, e.g.:
- A blank postcode - I'd like to handle this by displaying an alert dialog.
- A postcode supplied without a space is handled by inserting the missing space.
We're also in the process of upgrading our website to Google Chrome and MS Edge, so we need to use JavaScript where possible for scripting - I'd like to tell the user that the postcode is blank using the alert() function and I was thinking that the best way to do this would be as follows:
response.write("<SCRIPT language=" & chr(34) & "javascript" & chr(34) & ">alert('Please enter a postcode!');</SCRIPT>")
When I try this, I get one of two outputs in the input text box on the page where the result is saved:
- An HTML-formatted error message like: Microsoft VBScript compilation error '800a0400' Expected statement line 14
- The <SCRIPT> tag.
I've also tried using %> and %< tags around a <SCRIPT> tag, which is most likely what gives me the second output (I'm typing this on my personal computer and the testing environment is on my work computer).
I've been looking at a couple of other questions on StackOverlow and Internet searches:
- Display MessageBox in ASP
- Classic ASP: Microsoft VBScript compilation error '800a0400' Expected statement
Is there anything I've missed as I'd like to use alert() and the MsgBox() function doesn't work, which I found out when I tried it earlier.
%>work with the HTML be itscripttags etc then break back into the ASP code using<%. Remember that ASP code blocks need to start and end with<%and%>.