View Full Version : Assigning multiple name=values with one select box...help?

06-03-2005, 01:39 AM
I'm not sure how to do this as I am NOT a javascript Guru. But if I were to have a select box, and multiple options, how would I assign two different name=value combinations to that select box to be passed onto the next page and have them change as the user changes their choice in the select box?

i.e. I have a variable named "currency" and a variable named "amount"

when the user selects a new currency in the select box the values of both "currency" and "amount" change to accomodate the user's choice without reloading the page, and have both variables be passed on via the form.

How do I do this?

Any help is greatly appreciated!

)O( Cloudrunner )O(

06-03-2005, 11:45 PM
Anyone...Truth is I'm Javascript stupid folks, and I have not a CLUE on how to get this to work properly....

I have this thus far, and while it works in a standalone presence, when I try to add it to other pages, it chokes and I get nothing...

This is the test page...

<script language="javascript">
function makeAmount(){
var selVal = document.donate.currency_code[document.donate.currency_code.selectedIndex].value;
if (selVal == 'USD') document.donate.amount.value = 5;
else if (selVal == 'AUD') document.donate.amount.value = 10;
else if (selVal == 'CAD') document.donate.amount.value = 15;
if (empty($_POST)){
<form name="donate" action="test.php" method="post">
<input type="hidden" name="amount" value="1">
<select name="currency_code">
<option value="USD">US Dollar $5</option>
<option value="AUD">Australian Dollar = $10</option>
<option value="CAD">Canadian Dollar = $15</option>
<input type="submit" onClick="makeAmount()">
} else {
echo $_POST['currency_code']." -- ".$_POST['amount'];
?>Like I said, when I run this it works fine, but when I try to go live with it on a real page with true html / xml constructs, it chokes, no errors, but the "amount" variable is not passed within the $_POST global as if the form wrote it which is what I need to do...

Any help is appreciated...


)O( Cloudrunner )O(

Harry Armadillo
06-04-2005, 07:07 AM
A submit can be triggered by pressing enter, as well as clicking. So having your function as an onclick on the submit button is shaky. Better would be to have it as an onchange on the select, or as an onsubmit on the form.

If that doesn't help, post back showing the code of the non-working page.