Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Using getElementById() to get values from drop down list
Old 01-04-2011, 10:35 PM Using getElementById() to get values from drop down list
Junior Talker

Posts: 1
Name: Jane
Trades: 0
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>
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>
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
arch_devil is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-05-2011, 02:33 PM Re: Using getElementById() to get values from drop down list
kai_strieder's Avatar
Novice Talker

Posts: 6
Name: Kai Strieder
Location: germany
Trades: 0
When you say "database", you mean something on the server, right?

If so, then handling a basic HTML FORM element should do it. No need to poke the DOM (via getElementById or such), because that it client-side stuff.

Unless you want to use some AJAX ninja magic to post the data to the server, but a FORM is totally sufficient for that.
__________________
:-:
Please login or register to view this content. Registration is FREE

:-:
Please login or register to view this content. Registration is FREE
kai_strieder is offline
Reply With Quote
View Public Profile Visit kai_strieder's homepage!
 
Old 01-05-2011, 03:08 PM Re: Using getElementById() to get values from drop down list
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And by Java do you really mean javascript.

Because Java and javascript are different things entirely.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-05-2011, 05:12 PM Re: Using getElementById() to get values from drop down list
Novice Talker

Posts: 8
Trades: 0
PHP Code:
<select id="instance2" name="instance2">      
<
option value="0" default>All instances</option>      
<
option value="1">Item0</option>      
<
option value="2">Item1</option>      
<
option value="3">Item2</option>
</
select>

<
script>
  function 
getSelectedValue()
  {
    
selectBox document.getElementById("instance2");
    
alert(selectBox.value);
  }
</script> 
Hope thats what u r looking for
__________________
Feel free to chat/contact me through

Please login or register to view this content. Registration is FREE
Helper_24 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using getElementById() to get values from drop down list
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19496 seconds with 12 queries