By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Get php dropdown selected item value in javascript

P: 250
I want to take the drop down selected value using javascript.
This is dropdown code
Expand|Select|Wrap|Line Numbers
  1. <select id="user">
  2.     <option >Admin</option>
  3.     <option >User</option>
  4.     <option >Guest</option>
  5. </select>
This is the button which is used to call javascript function
Expand|Select|Wrap|Line Numbers
  1. <input name="usr" src="submit.jpg" type="image"  alt="submit" onclick="javascrpit:newwindow(); return false;"  />
This is javascript code
Expand|Select|Wrap|Line Numbers
  1. function newwindow(){
  2. var usr = document.getElementById('user').options[document.getElementById('user').selectedIndex].value
  4. }
I didn't get drop down selected value? Could somebody help me?
Aug 10 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
first… wrong forum.

second, there is a typo in your onclick event (2nd box).

third, the function (3rd box) can be drastically simplified by using the this keyword.
Aug 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.