Solved

why Jquery return drop down value as undefine

Posted on 2014-12-02
5
114 Views
Last Modified: 2014-12-03
var previousHead ;
   $('select[id^=no]').focus(function(e){
       previousHead = $(this).val(); 
alert(previousHead );
       
    });

Open in new window


they alert always showing as undefined  why ?????
0
Comment
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 40477955
What browser are you using?
This fiddle (http://jsfiddle.net/zm7uxxhx/) works using Chrome and IE11.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40478113
chrome and firefox
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 40478170
Have you tested the example provided? I tested it in Firefox and it work there as well.
Can you confirm that the example is working? Do you have options in the selectbox?
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40478222
No its not working for some time
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40478226
try this :
window.previousHead=null;
   $('select[id^=no]').focus(function(e){
       previousHead = $(this).val(); 
alert(previousHead );
       
    });

Open in new window

or this :
var previousHead ;
   $('select[id^=no]').mouseover(function(e){
       previousHead = $(this).val(); 
alert(previousHead );
       
    });

Open in new window

and finally try this if you load with ajax :
var previousHead ;
   $(document).on("focus", 'select[id^=no]', function(e){
       previousHead = $(this).val(); 
alert(previousHead );
       
    });

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now