Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

why Jquery return drop down value as undefine

Posted on 2014-12-02
5
Medium Priority
?
129 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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

963 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