Solved

why Jquery return drop down value as undefine

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

778 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