Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass on avlues from drop-down box

Status
Not open for further replies.

Nazgulero

IS-IT--Management
Oct 24, 2003
45
0
0
NL
Hello all,

I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want to pass those values, which come from the drop down box, to the next page. The next page should then simply look like this:

Month:

Year:

And the values should be the ones from the drop-down box...
I have been staring myself blind about how to get this accomplished. Would be more than grateful if somebody could have a look...

<script language="JavaScript"><!--
function setForm2Value() {
var selectedItem = document.formName1.selectName1.selectedIndex;
var selectedItemValue = document.formName1.selectName1.options[selectedItem].value;
var selectedItemText = document.formName1.selectName1.options[selectedItem].text;

if (selectedItem != 0) {
document.formName2.textboxName1.value = selectedItemText;
document.formName2.textboxName2.value = selectedItemValue;
}
else {
document.formName2.textboxName1.value = "";
document.formName2.textboxName2.value = "";
}
}
//--></script>
Incident Level <br>
<form name="formName1">
<select name="selectName1" onChange="setForm2Value()">
<option>Make A Selection:
<option value="2000">January
<option value="2001">February
<option value="2002">March
</select>
</form>

<p>

<form name="formName2">

<input type="text" name="textboxName1" value="" size="20"> Euro
<input type="text" name="textboxName2" value="" size="6">
</FORM>

Regards,

Naz
 
The first thing you should do is give form2 an action - which would be the filename of the next page.

Then, if you want to automatically pass the values to the next page on selection, then add this to the end of your setForm2Value function:

Code:
document.forms['formName2'].submit();

If you don't want it to be done automatically, then just add a submit button to the second form.

Then, on your next page, you can parse the submitted form variables.

If you have access to a server-side language, you should use this. If not, you'll have to post the form using the get method, and skim the details off of the URL.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,

thanks a bunch for your quick answer.

I have tried to add an action to form2 and a button, but nothing is happening...

<form name="formName2">
--><FORM METHOD="POST" ACTION="next_page.htm">
<input type="text" name="textboxName1" value="" size="20"> Euro
<input type="text" name="textboxName2" value="" size="6">
--><INPUT TYPE="submit" VALUE="Next Page" class=button>
</FORM>

Also, where exactly in the code do I have to add

document.forms['formName2'].submit();

?

I apologize for stupid questions, maybe I have been looking at this for too long...

Regards,

Naz
 
Hello Dan,

thanks again for your help. When I add the code where you indicated, my drop down list does not work anymore, that is, when I select anything from the list, it is not displayed in the text boxes...
I will play around with this some more...

Regards,

Naz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top