473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

getElementById('element').innerHTML query

Hi
Sorry about the heading.
I have a table with td consisting of lists with <select></select>. When
I do a document.getElementById("element").innerHTML I don't see the
selected item. IOW, the innerHTML is not dynamic. Is there some way to
get the most recent selected without traversing through the list's
options.

Thank you

Jul 23 '05 #1
3 5251
Unless I don't understand the question, I'm not sure why you're using
innerHTML at all for this.
Try
document.FORMNAME.SELECTELEMENTNAME.options[document.FORMNAME.SELECTELEMENTNAME.selectedindex].value
replacing FORMNAME and SELECTEDELEMENTNAME with the appropriate names you've
chosen.

<so***********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi
Sorry about the heading.
I have a table with td consisting of lists with <select></select>. When
I do a document.getElementById("element").innerHTML I don't see the
selected item. IOW, the innerHTML is not dynamic. Is there some way to
get the most recent selected without traversing through the list's
options.

Thank you

Jul 23 '05 #2
so***********@yahoo.com wrote:
Hi
Sorry about the heading.
I have a table with td consisting of lists with <select></select>. When
I do a document.getElementById("element").innerHTML I don't see the
selected item. IOW, the innerHTML is not dynamic.
There is no specification for how innerHTML works, it is not a
standard. Many browsers implement it but only through reverse
engineering of Microsoft's implementation (or perhaps their own
version of what they thing Microsoft's should do). Therefore
expecting it to have any particular behaviour is wishful thinking,
though it has been implemented reasonably consistently as far as I
know.

The following is therefore pure speculation based on observation.

innerHTML reflects the current HTML of the element. The 'selected'
attribute of an option sets the *default* selected element, it does
not necessarily reflect the currently selected element.

The user selecting an option does not change the default selected
element, therefore the innerHTML of the select does not change. If
you change an element - say using DOM methods - then the innerHTML is
modified.
Is there some way to
get the most recent selected without traversing through the list's
options.


The value of the currently selected option, in some browsers, can be
accessed by getting the select's value. However, some browsers
don't support that and you must use the 'selectedIndex' property.
For multiple selects, you must iterate through the options to find
the selected items.

It would be nice if there was a 'getSelectedOptions' method that
returned an array of the selected options, but alas, there ain't.

<script type="text/javascript">

function showValue( b ) {
var f = b.form;
var sel = f.elements['sel0'];
alert(sel.value);
alert(sel[sel.selectedIndex].value);

}

</script>
<form action="">
<select name="sel0">
<option value="option 0" selected>Option 0</option>
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
</select>
<input type="button" value="Show value..." onclick="
showValue(this);
">
</form>


--
Rob
Jul 23 '05 #3

Do it through the FORM of the select tag, not the table, and as the other
fellas already said, use .selectedIndex.

Danny

On Fri, 01 Jul 2005 12:33:23 -0700, <so***********@yahoo.com> wrote:
Hi
Sorry about the heading.
I have a table with td consisting of lists with <select></select>. When
I do a document.getElementById("element").innerHTML I don't see the
selected item. IOW, the innerHTML is not dynamic. Is there some way to
get the most recent selected without traversing through the list's
options.

Thank you


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
2
by: Dave Hammond | last post by:
I've got what should be a simple assignment of either an element value or a default string to a variable, but when the element doesn't exist I get an "Object required" error rather than an...
9
by: s_m_b | last post by:
I'm trying to get an <a> element to gain the focus onload, but only get back 'has no properties'. Reading through this ng, its clear that unless the element is within a form, this doesn't happen,...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
7
by: Daz | last post by:
Hi everyone! Is it possible to take a line of text like so: <tr><td>title1</td><td>title2</td><td>title3</td><td>title4</td></tr> And append it to a DOM node such as this: var...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
1
by: WFTomba | last post by:
Please forgive my ignorance. I've read a lot of reference and instructional materials but I need a couple of basic things clarified. Suppose, in JavaScript, I do like so: var a,b;...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.