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

changing select object value in a function

P: n/a
I have a form with a pull-down list with six options, each of which has
a value set. The value is the e-mail account name (without the domain)
of a group while the displayed value is the full name of the group that
will receive the e-mail.

I pass this.form to a function to validate the other data before handing
it off to a script to actually do the mailing. The mailer script looks
at all of the form's fields and sends their names and values as the
e-mail body.

All of this works. I get an e-mail sent to the correct group's account
with all the relevant information they are to receive.

However, I would like to include the full name of the group in the
e-mail as well. Since I don't need the e-mail account name, I thought
simply replacing it with the full name would be simple. However, it
seems to not be quite so easy.

This.form is passed to the validation script as aform.

alert(aform["Account"].value);
shows the expected account value within the validation script.

aform["Account"].value="some test value";
alert(aform["Account"].value);
shows the original value. The assignment doesn't seem to work.

Can someone explain why the assignment isn't working?
Feb 5 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
On Feb 5, 11:58 am, Gary Dale <garyd...@rogers.comwrote:
I have a form with a pull-down list with six options, each of which has
a value set. The value is the e-mail account name (without the domain)
of a group while the displayed value is the full name of the group that
will receive the e-mail.
[...]
However, I would like to include the full name of the group in the
e-mail as well. Since I don't need the e-mail account name, I thought
simply replacing it with the full name would be simple. However, it
seems to not be quite so easy.

This.form is passed to the validation script as aform.

alert(aform["Account"].value);
shows the expected account value within the validation script.

aform["Account"].value="some test value";
alert(aform["Account"].value);
shows the original value. The assignment doesn't seem to work.

Can someone explain why the assignment isn't working?
I'll guess that Account is the name of the select element. Select
elements don't have a value attribute specified in the W3C HTML 4
specification, it comes from the selected option(s) and is reflected
in the W3C DOM HTML Spec:

"The current form control value (i.e. the value of the currently
selected option), if multiple options are selected this is the
value of the first selected option."

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-59351919 >
What happens when you assign a value to the select's value attribute
is not defined anywhere, perhaps it is simply ignored. If you want to
change the value of the select, you have to change the value of the
selected option.

You might find it easier to do the substitution elsewhere in your
code. I'm not sure it's suitable to re-map values in a validation
function, it seems more appropriate to do it in a down-stream function
that processes the content of the form.
--
Rob

Feb 5 '07 #2

P: n/a
RobG wrote:
On Feb 5, 11:58 am, Gary Dale <garyd...@rogers.comwrote:
>I have a form with a pull-down list with six options, each of which has
a value set. The value is the e-mail account name (without the domain)
of a group while the displayed value is the full name of the group that
will receive the e-mail.
[...]
>However, I would like to include the full name of the group in the
e-mail as well. Since I don't need the e-mail account name, I thought
simply replacing it with the full name would be simple. However, it
seems to not be quite so easy.

This.form is passed to the validation script as aform.

alert(aform["Account"].value);
shows the expected account value within the validation script.

aform["Account"].value="some test value";
alert(aform["Account"].value);
shows the original value. The assignment doesn't seem to work.

Can someone explain why the assignment isn't working?

I'll guess that Account is the name of the select element. Select
elements don't have a value attribute specified in the W3C HTML 4
specification, it comes from the selected option(s) and is reflected
in the W3C DOM HTML Spec:

"The current form control value (i.e. the value of the currently
selected option), if multiple options are selected this is the
value of the first selected option."

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-59351919 >
What happens when you assign a value to the select's value attribute
is not defined anywhere, perhaps it is simply ignored. If you want to
change the value of the select, you have to change the value of the
selected option.

You might find it easier to do the substitution elsewhere in your
code. I'm not sure it's suitable to re-map values in a validation
function, it seems more appropriate to do it in a down-stream function
that processes the content of the form.
--
Rob
OK, I can see that changing the value of the selected option at the
"select" level might confuse javascript - but the value is not listed as
read-only. It seems to me that if it doesn't allow the value to be
changed, it should list it as read-only.

Anyway, I am now using the selectedIndex to replace the selected
option's value with its text. That looks cleaner and it works. Thanks!

As for the coding style, I could make the code into three functions with
one passing things to a validator, modifying the form then passing it
down to a mailer, but that seems like overkill. All I'm testing for is
"are fields filled in?"

The mailer is more complex because it walks the form looking for values
to put into the message body.

And the bridge code is just three lines. :)

Thanks again for your help!
Feb 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.