Solved

why Jquery return drop down value as undefine

Posted on 2014-12-02
5
116 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

867 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

25 Experts available now in Live!

Get 1:1 Help Now