I want to call the ajax function once user clicks on the select control or the select control gets focus to itself from keyboard. HTML code is as follows :
Solution 1:
In your code i haven't seen any options for html select box
And, you have registered a change event on select box which will occur only on selecting the options in select box
Add few options in select box and try to select options which will fire the ajax call
See JS FIDDLE HERE
Solution 2:
I think you should do this instead:
$("#scanner").bind("focus", function() {
alert("Hello");
var mod_url = $('#mod_url').val();
$.ajax({
url : mod_url,
cache: false,
dataType: "html",
type: "GET",
data: {
'request_type':'ajax',
'op':'get_all_stores'
},
success: function(result, success) {
alert(result);
$('#scanner').html(result);
},
error: function() {
alert("Error is occured");
}
});
});
Copy
And one suggestion about bind is, you can use .on() method instead if you are using jQuery version 1.7+.
What seems to me you want to generate your #scanner elements options by your ajax call, so the changes are:
remove the async:false because ajax has to be asynchronous.
change the dataType to html because it seems that you are returning options from there as $('#scanner').html(result); suggests.
Solution 3:
I Think This is what you want
$("#scanner").bind('focus',function () {
Myfunction(); // call what you want to call on focus
}).change(function() {
Myfunction() // call what you want to call on Change
});
function Myfunction()
{
var mod_url = "http://google.com";
$.ajax({
url : mod_url,
cache: false,
dataType: "json",
type: "GET",
async: false,
data: {
'request_type':'ajax',
'op':'get_all_stores'
},
success: function(result, success) { alert(result);
$('#scanner').html(result);
},
error: function() {
alert("Error is occured");
}
});
}
Copy
here js fiddle DEMO
Share
Post a Comment
for "Why The AJAX Function Is Not Getting Called And Alert Is Not Getting Printed Upon Calling The Function?"
Top Question
How To Detect Android's Version Number In Firefox For Android?
For a website we want to show a link in the play store if t…
Display Array Of Objects In A Dynamic Table Javascript
I want to display an array of objects in a dynamic table us…
Modal Appears On Page Load
Following is my code but the modal only appears when someon…
D3 Animating A Bubble Chart Within A Given Radius
//bubble chart base. http://jsfiddle.net/NYEaX/1450/ I am t…
Passport-Google-OAuth Callback Not Working When Used In Web Service
I Have used Passport-Google-OAuth in Node.js web service pr…
Synchronized Multiple API Calls
I need to fetch the data from two different API endpoints, …
Passport-Google-OAuth Callback Not Working When Used In Web Service
I Have used Passport-Google-OAuth in Node.js web service pr…
Javascript Regex Phone Validation
Can anyone suggest a js function to validate a phone number…
How To Place " ...view More " Text Next To The Truncated Sentence In A Container-Javscript
I want to show a '...more' text for a long name des…
How To Limit The Html Table Records In Each Page
I am populating a table in my jsp which has more than 20 re…
December 2024
(1)
November 2024
(38)
October 2024
(54)
September 2024
(18)
August 2024
(210)
July 2024
(191)
June 2024
(388)
May 2024
(673)
April 2024
(428)
March 2024
(767)
February 2024
(917)
January 2024
(771)
December 2023
(793)
November 2023
(313)
October 2023
(520)
September 2023
(286)
August 2023
(325)
July 2023
(280)
June 2023
(373)
May 2023
(206)
April 2023
(138)
March 2023
(144)
February 2023
(184)
January 2023
(259)
December 2022
(129)
November 2022
(233)
October 2022
(154)
September 2022
(165)
August 2022
(502)
July 2022
(287)
June 2022
(294)
Menu Halaman Statis
Beranda
© 2022 - JavaScript Info