codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Using getElementById() to get values from drop down list  arch_devil at 02:27 on Wednesday, January 05, 2011
 

Hi, I'm a beginner at java, still learning, so have some patience with me :) I have this .java page which should get and set a HtmlPage, and this HtmlPage has a drop down list with values(I use firebug in Mozilla firefox to inspect this element), and this code is what appears in the firebug inspection window:

[code]<select id="instance2" name="instance2">
<option value="0">All instances</option>
<option value="1">Item0</option>
<option value="2">Item1</option>
<option value="3">Item2</option>
.
.
.
<option value="23">Item22</option> [/code]

What I want to do is actually to get the value that a user has selected from the drop down list, and save it to the database, and someone told me I could use getElementById(), and I have this code that I found on the internet:

[code]<select name="mySelect" id="mySelect" onchange="getSelectedValue();">
<option value="1">Text 1</option>
<option value="2">Text 2</option>
</select>

<script type="text/javascript">
function getSelectedValue() {
var index = document.getElementById('mySelect').selectedIndex;
alert("value="+document.getElementById('mySelect').value);
alert("text="+document.getElementById('mySelect').options[index].text);
}
</script> [/code]

I really need help here because it's urgent, and I've been to many other forums, but there are people telling me that it's I should go either java or javascript forums. Please tell me if I'm at the right forum and if not, which one I should go to.

Thanks, any help is greatly appreciated :)








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Cascading Menu
•  Re: How to populate a drop down list from a DB
•  Re: Javascript Disable
•  Re: Need some help with javascript code in Unity!
•  Create anExpanding/Collapsing Tree Menu for this Tutorial
•  Creat A Calendar With PHP
•  Re: How to access style attributes in DOM using Javascript?
•  Re: Javascript foldout menu help!
•  Ask for Help!


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2011