dave
dave

Reputation: 1733

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').val('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');
    });

Upvotes: 3

Views: 17980

Answers (6)

tamil arasan
tamil arasan

Reputation: 64

$.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..!!");
   }
});

Upvotes: 0

Devi
Devi

Reputation: 55

$('#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 :)

Upvotes: 0

dave
dave

Reputation: 1733

it worked, the error was, there was no id for the textbox

<input type='text' name='text' id='text'>

Thanks all of you..

Upvotes: 0

rahul
rahul

Reputation: 187030

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('');

Upvotes: 0

Devi
Devi

Reputation: 55

    $(function(){
       $('#btnSubmit').bind('click', function(){
           $('input#c_album').val('hello');
// OR
           $('#c_album').val('hello');
// OR
           $('input[id=c_album]').val('hello');
       });
   });

Upvotes: 3

Chris
Chris

Reputation: 6638

$(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.

Upvotes: 0

Related Questions