I have a query string that I’m trying to pass onto another page. When I enter the url string into a browser, it works fine, the data is passed. However, when trying to formulate the string using Java Script, it does not pass. Could you please check this line of code and let me know if it looks ok.
The Javascript code I’m using:
window.location = 'http://www.domain.com/test.asp?FirstName=' + escape(document.getElementById('FirstName').value);
The url that needs to be produced that works if I put in manually into the browser:
http://www.domain.com/test.asp?FirstName=John
A bit of background info on the java script purpose. I am using java script to create and validate a form, rather than using form tags on my main page. The rest of the javascript code is simple and should not be the cause. Just in case, I’ve included the code minus the extra form fields.
function ValidateForm() {
var isFormValid = 1;
var errorMessage = '';
var firstName = document.getElementById('FirstName');
if(firstName.value.length < 1)
{
isFormValid = 0;
errorMessage = errorMessage + '- First Name is required.\
';
}
if(isFormValid == 0)
{
alert(errorMessage);
}
else
{
// Send the data and user to next step
window.location = 'http://www.domain.com/test.asp?FirstName=' + escape(document.getElementById('FirstName').value);
}
}
document.write('<table width="225" border="0" cellspacing="0" cellpadding="3" align="center" class="newform">');
document.write('<tr>');
document.write('<td height="50" width="60"></td>');
document.write('<td height="50" width="140"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td height="28" align="right" nowrap="nowrap">First Name</td>');
document.write('<td><input name="FirstName" id="FirstName" type="text" size="20"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td></td>');
document.write('<td><a href="http://www.domain.com/ThankYou.asp"><input name="SubmitButton" id="SubmitButton" type="image" onClick="return ValidateForm();" value="submit" src="images/newbutton.gif"></a>');
document.write('</td>');
document.write('</tr>');
document.write('</table>');
document.all('FirstName').focus();