Setting value for a textbox - jQuery
I want to set the value of a textbox to null via jquery. I tried
onclick="$('#c_album').val('TEST VALUE');" at the submit button
$('input#c_album').v开发者_如何学Goal('hello'); - in the script section
Appreciate assitance
Thanks Dave
[edit]-- this is the code i am using
$('#submit').bind('click',(function(){
$('#src_box').val('hello');
});
$(function(){
$('#btnSubmit').bind('click', function(){
$('input#c_album').val('hello');
// OR
$('#c_album').val('hello');
// OR
$('input[id=c_album]').val('hello');
});
});
$(function(){
$('#mybutton').click(function(e){
$('input#c_album').val('hello');
});
});
Is a general method which should work. Without knowing more of your code it's hard to be more specific.
If the id of the textbox is #c_alcum then you can use
$("#c_album").val('hello');
Although you can use a tag selector in front of the id selector, there is no need to use that since id will be unique in a document.
If you want to set the value after the ajax function completion then you can insert this code in the callback function for the ajax request.
Edit
Are you putting all these codes inside the document ready event
$(function(){
// All code goes here
});
Also remove the onlick handler and do it in jquery way like
$("#yourbuttonid").click ( function(){
});
or
$("#yourbuttonid").bind ( "click" , function() {
});
You can't put a null value inside a textbox. You can insert an empty string value inside it like
$("#c_album").val('');
it worked, the error was, there was no id for the textbox
<input type='text' name='text' id='text'>
Thanks all of you..
$('#submit').bind('click',(function(){
$('#src_box').val('hello');
});
There is a problem in this code, so try this -
$('#submit').bind('click',function(){
$('#src_box').val('hello');
});
The problem is you have used a '(' before the function(). But now it will work fine :)
$.ajax({
type: "GET",
url: "fetchBeaconName",
data: "beaconMajorId=" + val,
async: true,
success: function (data) {
$.each(data.beaconList, function () {
$("#beaconName").val(this.beaconName);
});
},
error: function (data) {
alert("No values found..!!");
}
});
精彩评论