...

View Full Version : Query Strings & Forms



dlg0351
03-22-2005, 12:39 AM
I have a simple form that accepts input into a text box, passes it to another html page using method="get" and displays the input on the screen to be verified before actual submission.

I have no probem getting the information to pass to the 2nd page, but I am not sure how I can get that information to actually be submitted.

Here is my code:

Page1 - this sends the info in the textbox to Page2.


<html>
<head>
<title></title>
</head>

<body>

<form name="myform" method="get" action="page2.html">
Enter Name: <input type="text" name="input1">
<input type="submit">
</form>

</body>
</html>



Page2 - this receives the input reading it from the address bar and displays it on the page.


<html>
<head>
<title></title>

<script LANGUAGE="JavaScript">
function decodeSearchString() {
var nameValue = new Array();
var searchStr = unescape(location.search.substring(1));
if (searchStr) {
var formElement = searchStr.split("&");
var tmpArray = new Array();
for (k = 0; k < formElement.length; k++) {
tmpArray = formElement[k].split("=");
nameValue[tmpArray[0]] = tmpArray[1];
}
}
return nameValue
}

var srchData = decodeSearchString();
</SCRIPT>
</head>

<body>

<form name="myform" method="post" action="WHATEVER">
<input type="hidden" name="subject" value="My Form">
<input type="hidden" name="next_url" value="WHATEVER">

<script>document.write(srchData.input1.replace(/\+/g, ' '));</script>
<input type="submit">
</form>

</body>
</html>


I cannot get the value of input1 to be submitted. I only receive the subject = My Form.

Any suggestions?

hemebond
03-22-2005, 03:41 AM
document.getElementById('hiddenInputElement').value = theValuePassedByURL;Of course, this should all be done via server-side scripting.

dlg0351
03-22-2005, 03:11 PM
What goes in the place of hiddenInputElement and theValuePassedByURL?



document.getElementById('hiddenInputElement').value = theValuePassedByURL;

hemebond
03-22-2005, 09:07 PM
<input type="hidden" id="hiddenInputElement" name="hiddenInputElement" value="">

<script type="text/javascript">
document.getElementById('hiddenInputElement').value = decodeSearchString();
</script>

dlg0351
03-23-2005, 02:49 AM
Great! That worked, but I do have some more questions.

The whole point in me having to use query strings is because the client that I am working on a site for does not pay for PHP as part of their hosting package, otherwise I would have used it.

To me this seems pretty straight forward, send info using a form and have your results displayed to you to verify and have the option to make changes or to submit. What other options are there to do this besides PHP or ASP?

Yes the solution you told me does work, however it does not work in older browsers that do not support getElementById.

Are there other options besides cookies? I am not familiar with cookies at all to use them as a solution, your thoughts?

hemebond
03-23-2005, 03:34 AM
Um. If you don't have server-side scripting capabilities, what are you going to do with the form?

dlg0351
03-23-2005, 03:50 AM
The form is just going to be submitted like any other form, the receiver would get the results of the form sent to them in an email.

I just want to be able to have the person filling out the form, in this particular case a simple order form, be able to view the information to verify it's accurancy and have a chance to go back and make any corrections and resubmit.

dlg0351
03-23-2005, 07:45 PM
I think I found an alternative to using:


<script type="text/javascript">
document.getElementById('input1').value = srchData.input1.replace(/\+/g, ' ');
</script>

Alternative:


<script type="text/javascript">
document.myform['input1'].value = srchData.input1.replace(/\+/g, ' ');
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum