Click to See Complete Forum and Search --> : Onchange event:


mili
12-04-2003, 10:06 AM
Hi, I'm trying change the value of a input text box and the selected value of a select box based on a value selected from another select box.
This doesnt seem to be working.When I choose USD from currencies, I want to change the Type to "Type USD" selected and the value in Amount text box from "bn" to "mn".
Am I doing something wrong in my Javascript?

Thanks

<html>
<head>
<title>Untitled</title>
<script language="JavaScript1.2">

function ccyScale ()
{
if(document.form1.ccy.options[document.form1.ccy.selectedIndex].text = "JPY")
{
alert(document.form1.ccy.options[document.form1.ccy.selectedIndex].text);
document.form1.amt.value = "bn";
document.form1.type.options[document.form1.type.selectedIndex].text = "Type JPY"
}
if(document.form1.ccy.options[document.form1.ccy.selectedIndex].text = "USD")
{
alert(document.form1.ccy.options[document.form1.ccy.selectedIndex].text);
document.form1.amt.value = "mn";
document.form1.type.options[document.form1.type.selectedIndex].text = "Type USD"
}
if(document.form1.ccy.options[document.form1.ccy.selectedIndex].text = "AUD")
{
alert(document.form1.ccy.options[document.form1.ccy.selectedIndex].text);
document.form1.amt.value = "mn";
document.form1.type.options[document.form1.type.selectedIndex].text = "Type AUD"
}
}

</script>
</head>
<body>
<form name="form1">
Currency :
<select name="ccy" onChange="ccyScale();" >
<option>JPY</option>
<option>USD</option>
<option>AUD</option>
</select>
<br>
<br>
<br>
<br>
Amount : <input type="text" name="amt1"> <input name="amt" type="text" disabled size="2" value="bn">
<br>
<br>
<br>
<br>
Type :
<select name="type">
<option>Type JPY</option>
<option>Type USD</option>
<option>Type AUD</option>
</select>
</form>
</body>
</html>

Pittimann
12-04-2003, 10:54 AM
Hi!

Your function could look like this (it could be abbreviated, but like this, it is easier to understand):

<script type="text/javascript">
function ccyScale () {
if(document.form1.ccy.selectedIndex == 0) {
document.form1.amt.value = "bn";
document.form1.type.selectedIndex=0;
}
if(document.form1.ccy.selectedIndex == 1) {
document.form1.amt.value = "mn";
document.form1.type.selectedIndex = 1;
}
if(document.form1.ccy.selectedIndex == 2) {
document.form1.amt.value = "mn";
document.form1.type.selectedIndex=2;
}
}
</script>

Cheers - Pit