Hello,
Had a very time consuming problem today. For some reason I don't know yet, my java script stopped reading values for <select> boxes in one of my forms. The other elements worked fine, only the value from the select was null.
Here is what I mean. I use a ciclyc function to read all the elements and values from a form. The function imports the value from the select only if I define the options like this: <option value="first">first</option>. If I do it like this: <option>first</option>, without value defined, it returns null.
Does anyone have an opinion?
Thanks,
Why do you need value in <select>?
Moderator: General Moderators
-
andrei.mita
- Forum Commoner
- Posts: 65
- Joined: Sun May 08, 2005 4:06 am
- Location: Barlad/Romania
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Why do you need value in <select>?
If you don't define a value, then what would you expect it to be? Of course it will be null 
(or did I misunderstand?)
(or did I misunderstand?)
Re: Why do you need value in <select>?
The reason for the value attribute is to give the option element a value. The value of an option element should be in it's value attribute and no where else.
The reason for the separation of the option element's value and it's textual appearance is for flexibility. For example, let's say you had the following:
As you can see here that without the value attribute there would be no way to determine what age we want.
In Javascript we can get the value of an HTML element using the element.value property. But if you'd like the "textual stuff", you'd use element.innerHTML or element.textContent.
Code: Select all
<option value="[i]value[/i]">[i]text element[/i]</option>Code: Select all
<select>
<option value="32">Joe's age</option>
<option value="23">Brian's age</option>
</select>
In Javascript we can get the value of an HTML element using the element.value property. But if you'd like the "textual stuff", you'd use element.innerHTML or element.textContent.
Re: Why do you need value in <select>?
I vaguely recall back when I used to use IE (ie6 i believe... maybe 7), that if you did not define a value, it would take the value of what's inside the option tag.
I could be wrong, but this is why I started making my selects have a default value, and then checking the values against expected values + the default value.
I could be wrong, but this is why I started making my selects have a default value, and then checking the values against expected values + the default value.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
andrei.mita
- Forum Commoner
- Posts: 65
- Joined: Sun May 08, 2005 4:06 am
- Location: Barlad/Romania
Re: Why do you need value in <select>?
I get it now. Thank's for the info. It still is very odd why it worket for a while and why it still works if I take out the form from and run it alone.
Anyhow, thanks a lot for the explenation, it's good I discovered this "bug" in my application at this early stage of the project.
Anyhow, thanks a lot for the explenation, it's good I discovered this "bug" in my application at this early stage of the project.