473,766 Members | 2,023 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 2020
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
2114
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
3013
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
24537
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
2294
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
2628
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
10499
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
3692
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
1844
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
19626
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
10168
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
10008
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...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
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
6651
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
5279
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.