473,695 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing select object value in a function

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
2 2017
On Feb 5, 11:58 am, Gary Dale <garyd...@roger s.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
RobG wrote:
On Feb 5, 11:58 am, Gary Dale <garyd...@roger s.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2109
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and automatically builds querystrings for my redirect URLS. The code for this follows. It defines an ASP Dictionary object, and key/value pairs for each, and builds appropriate querystrings based on comparison with a status variable. The way it works...
1
3011
by: Young-Soo Roh | last post by:
Hi. I need to get simple script working. I have many select object. When I select a different option, I would like to change the value of corresponding text input field. How can I do this using javascript? Here is what I have so far. <SELECT NAME=\"%s\" onChange=\"fill_desc(this.form, $name, $field_name)>
3
24533
by: jeff | last post by:
Hello, I have a form that submits it's values to a pop-up window. I've simplied the code: <form name="formname" action="action.php" target="windowName" method="post" onsubmit="window.open('', this.target, 'dialog,modal,scrollbars=yes,resizable=no,width=300,height=200,left=362,top=284');">
7
2289
by: Hal Vaughan | last post by:
I have a sample script from a book ("Beginning JavaScript" by Paul Wilton) that removes or adds a choice to a <SELECT> element. The <FORM> is form1 and the <SELECT> is theDay. The example uses these lines (full text is below): if (document.form1.theDay.options.text != "Wednesday) { var days = document.form1.theDay; days.options.text = days.options.text; <snip> var option - new Option("Wednesday", 2);
2
2623
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the form is opened. After the user selects the contact from an unbound combobox I want the form to be rebound to its recordsource. I tried using form.recordsource = "Contacts" in the afterupdate event of
6
10489
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be done without API calls? Thanks Ioannis
32
3674
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's RecordSource like this? Am I asking for trouble doing this with a memo field? Thanks in advance. Private Sub cmdNextNote_Click() Dim lngNid As Long If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
4
1836
by: Siah | last post by:
Hi, I wanted to dynamically update pieces of my page in the following fashion. Look at the following html code: <span id='person_23_name'> Mike </span> <span id='person_28_name'> Siah </span> <span id='person_23_name'> Mike </span> Now, I want to update the name of person #23 (person_24_name)
4
19620
by: Robert Bravery | last post by:
HI all, In JS, how can I change the selected value of a dropdownlist(select options) I know the value of indexed value of the selected value before it is changed. Thanks Robert
0
8617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8822
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6483
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4570
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.