Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why Jquery return drop down value as undefine

Posted on 2014-12-02
5
Medium Priority
?
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

704 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