PDA

View Full Version : onchange event help needed...


Cloudrunner
06-02-2005, 11:24 PM
I need to have two variables get assigned when a user changes the setting of a select box. I'm not sure how to do this, but I am thinking that the onchange value in select can do what I am looking for it to do.

i.e. I have one select box <select name="whatever" onchange="*something here*">
<option>Option1</option>
<option>Option2</option>
</select>and have it set two variables $x and $y to a default value just in case the user doesn't change the selection, while if the user does change the selection, then both the variables $x and $y change accordingly for each option.

I'm not a javascript guru, so I don't know how to do this, if anyone can assist here I would appreciate it. I don't want to have two select inputs on this...

Thank you!

)O( Cloudrunner )O(

this needs to be done without reloading the page, and in a form name=variable system so that I can pass that information to the next script via the $_POST variable...

anyone?

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;
}
</script>
<?
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>
</select>
<input type="submit" onClick="makeAmount()">
</form>
<?
} 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...

Thanks

)O( Cloudrunner )O(

Cloudrunner
06-05-2005, 03:48 AM
I need to have two variables get assigned when a user changes the setting of a select box. I'm not sure how to do this, but I am thinking that the onchange value in select can do what I am looking for it to do.

i.e. I have one select box <select name="whatever" onchange="*something here*">
<option>Option1</option>
<option>Option2</option>
</select>and have it set two variables $x and $y to a default value just in case the user doesn't change the selection, while if the user does change the selection, then both the variables $x and $y change accordingly for each option.

I'm not a javascript guru, so I don't know how to do this, if anyone can assist here I would appreciate it. I don't want to have two select inputs on this...

Thank you!

)O( Cloudrunner )O(

this needs to be done without reloading the page, and in a form name=variable system so that I can pass that information to the next script via the $_POST variable...

anyone?

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;
}
</script>
<?
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>
</select>
<input type="submit" onClick="makeAmount()">
</form>
<?
} 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...

Thanks

)O( Cloudrunner )O(
NVM, got it figgered out.