PDA

View Full Version : Form Display Issue


RichieRichR6
04-02-2007, 10:34 PM
Hi all,

I'm pretty new to javascript. Please help me. I'm having a very hard time with my form to display correctly on the 2nd page. If a user skips a field on the 1st page, it throws my data off on the second page. Please see my link below.
http://mason.gmu.edu/~jwray/final_project.html

What am I missing? My eyes hurt searching for this error I've made in my code.

Thanks,

rwedge
04-02-2007, 11:54 PM
You query string looks ok on page 2 and if your form element names stay the same between pages,
this example would target the input elements by id:
<script type="text/javascript">
/*<![CDATA[*/
function retrieveData() {
var loc= 'final_page2.html?state=denile&birth=2000AD&submit=submit';
var searchString = loc.substring((loc.indexOf('?')) + 1);
// var searchString = location.substring((location.indexOf('?')) + 1);
var keypairs = new Array();
var i = 0;
while (searchString.indexOf('&') > -1) {
keypairs[i] = searchString.substring(0,searchString.indexOf('&'));
searchString = searchString.substring((searchString.indexOf('&')) + 1);
i++;
}
for (i = 0;i<keypairs.length;i++) {
var val = keypairs[i].split('=');
document.getElementById(val[0]).value=val[1];
}
}
window.onload=retrieveData;
/*]]>*/
</script>


<form name="address2" id="address2" action="final_page3.html" enctype="multipart/form-data">
State <input type="text" name="state" id="state" value="" size="" maxlength="50" /><br />
Birthdate(mm/dd/yyyy): <input type="text" name="birth" id="birth" value="" size="16" maxlength="20" />
</form>test code in blue

RichieRichR6
04-03-2007, 01:06 AM
LOL, state=denile!!!