By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,690 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.

if then to change a parameter in javascript

P: n/a
The following information is passed to a script to generate an email
from a form.
<INPUT TYPE="hidden" name="param_recipient" value="me@mycompany.org">

In the form further down on the page, a user enters a value in the ru
field. I want to write something similar to:
if ru=122 then sendformto="me@mycompany.org"
if ru=144 then sendformto="yo*@mycompany.org"

the paramater above would then become something like:
<INPUT TYPE="hidden" name="param_recipient" value=sendformto>

How would I go about doing this?

Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
There are many ways to go about doing this, but here's what I'd do.

I'd give the form an onsubmit event handler, like so:

onsubmit="decideWhoToMailTo(this);"

The decideWhoToMailTo function would contain code like the following:

function decideWhoToMailTo(form) {
if (form.ru.value == "122") {
form.form.param_recipient = "ad******@mydomain.com";
} else if (form.ru.value == "144") {
form.param_recipient = "ad******@mydomain.com";
}
}

....Then, I'd probably wonder why I bothered coding any Javascript at
all, when all the processing could easily be done on the server end.

Dec 1 '06 #2

P: n/a
It wasn't working, so I made some small changes to test. 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 #3

P: n/a
TeknoShock wrote:
It wasn't working, so I made some small changes to test. 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";
}

}
function decideWhoToMailTo(dform) {
var d=dform.ru;
dform.param_pie.value=
d.value == "122"?"me@mycompany.org":
d.value == "144"?"yo*@mycompany.org":"no email";
}

Mick
</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 #4

This discussion thread is closed

Replies have been disabled for this discussion.