By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Change value of one variable based on user input of another value

P: n/a
I am trying to use an if then in javascript to change one value based
on what a user inputs for another value. It is not working correctly.
Here is the relevant code:
---------------------------
<script language="javascript" >

function decideWhoToMailTo(dform) {
if (document.dform.ru.value == "122") {
document.dform.param_pie = "me@mycompany.org";
} else if (document.dform.ru.value == "144") {
document.dform.param_pie = "yo*@mycompany.org";
}

}

</script>
-----------------------------
<FORM name="dform"
ACTION="http://intranet.mycompany.org/cgi-bin/purchase2.pl" METHOD=POST

onsubmit="decideWhoToMailTo(this);" >

<INPUT TYPE="hidden" name="param_pie">
RU: <input type="text" name="ru" value="122" tabindex="2">
----------------------------
I then passed the param_pie to the cgi script just to see what it is
being set to. It is being set to blank.

Can you see where I went wrong? I am leaving the ru set to the default

value of 122, so I would expect param_pie to be set to me@mycompany.org.

Dec 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
VK
<script language="javascript" >
>
function decideWhoToMailTo(dform) {
if (document.dform.ru.value == "122") {
document.dform.param_pie = "me@mycompany.org";
} else if (document.dform.ru.value == "144") {
document.dform.param_pie = "yo*@mycompany.org";
}

}

</script>
-----------------------------
<FORM name="dform"
ACTION="http://intranet.mycompany.org/cgi-bin/purchase2.pl" METHOD=POST

onsubmit="decideWhoToMailTo(this);" >

<INPUT TYPE="hidden" name="param_pie">
RU: <input type="text" name="ru" value="122" tabindex="2">

1) dform is a direct reference to your form, no document reference is
needed.

2) form control value is changed over it .value property
<script type="text/javascript" >

function decideWhoToMailTo(dform) {
if (dform.ru.value == "122") {
dform.param_pie.value = "m...@mycompany.org";
} else if (dform.ru.value == "144") {
dform.param_pie.value = "y...@mycompany.org";
}
}

</script>

Dec 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.