easiest way would be a function called from the onload event of the body tag:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> new document </title>
<script type='text/javascript'>
<!--
function setField() {
var qString = location.search;
if (qString.indexOf('frmdate') != -1) {
var data = qString.substring(qString.indexOf('=') + 1, qString.length);
document.forms[0].myDate.value = data;
}
}
//-->
</script>
</head>
<body onload='setField()'>
<form method=post action="">
<input type="text" name="myDate">
</form>
</body>
</html>
Now this will only work if that frmdate is the ONLY variable coming in because of the substring being used on the “=” (IE frmdate=data) … if there is more than one variable you would have to get the position of frmdate and then move it over to get the value after it…
You can also change the document.forms[0] to the form name if you have it named … IE your form has name=‘myForm’ in the form tag you would then change the js to document.myForm.myDate.value =
OK heres a new version that first finds the variable in the query string and then grabs its value…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> new document </title>
<script type='text/javascript'>
<!--
function setField() {
var qString = location.search; // get the query string
if (qString.indexOf('frmDate') != -1) { // find out if the field frmDate is present
var requiredData = qString.indexOf('frmDate='); // get the postion in the query string of frmDate
var data = qString.substring(requiredData + 8, qString.length); // grab everything in the query string AFTER frmDate
if (data.indexOf('&') != -1) { // check to make sure there are no other variables AFTER the frmDate variable
data = data.substring(0, data.indexOf('&')); // if there is more data after it chop it off
}
document.forms[0].myDate.value = data; // assign the proper data to the form field
}
}
//-->
</script>
</head>
<body onload='setField()'>
<form method=post action="">
<input type="text" name="myDate">
</form>
</body>
</html>
Ive broken all the variable and substrings in to their own steps to help you understand it even though the code COULD be condensed quite a bit… didnt want to confuse you!
Yeah split() is fine for more advanced users but this person seems (i think even said) they are a beginner so I figured the KISS method was the best :agree: