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 boxAnd, you have registered a change event on select box which will occur only on selecting the options in select boxAdd few options in select box and try to select options which will fire the ajax callSee JS FIDDLE HERESolution 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
});
functionMyfunction()
{
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");
}
});
}
Copyhere 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
Easiest Way In R Or Python To Add Image/video In Map Plot Marker Click Popup/infowindow
I have many different (lat,long data) points of world assoc…
Dropdown Options Is Dependent From Another Dropdown Options (all Value From Database)
how can i do this. if i select in first dropdown hand spa, …
Js Function With Two Parentheses And Two Params
I'm trying to understand how a function works that is r…
Simple Example With Window.requestFileSystem() Function
I have next problem: I try to use window.requestFileSystem(…
IE 11 Browser Recognizes Itself As Mozilla
I am working on MVC application, .net 4.5 framework, VS 201…
JQuery Checking A Checkbox And Triggering Javascript Onclick Event
I'm trying to check a checkbox using jQuery and trigger…
JavaScript - Uncheck Check Box On Mouseup
I'm trying to implement a simple 'show password'…
Drag And Drop From Image Onto Another Image
I wanted to drag and drop image onto another image. I canno…
HTML5 Slider With Onchange Function
I have a slider (input type range) that is supposed to run …
Reading In A File From Ubuntu (aws Ec2) On Local Machine?
I have a python script which I'm running on AWS (EC2 in…
December 2024
(1)
November 2024
(39)
October 2024
(72)
September 2024
(22)
August 2024
(366)
July 2024
(343)
June 2024
(715)
May 2024
(1296)
April 2024
(809)
March 2024
(1541)
February 2024
(1699)
January 2024
(1338)
December 2023
(1393)
November 2023
(421)
October 2023
(599)
September 2023
(276)
August 2023
(342)
July 2023
(265)
June 2023
(356)
May 2023
(214)
April 2023
(123)
March 2023
(149)
February 2023
(182)
January 2023
(275)
December 2022
(125)
November 2022
(236)
October 2022
(181)
September 2022
(163)
August 2022
(499)
July 2022
(286)
June 2022
(308)
Menu Halaman Statis
Beranda
© 2022 - javascript nyumon