Skip to content Skip to sidebar Skip to footer

Change A Hidden Input Fields Value When A Radio Button Is Selected

I want to change the value of an hidden input field each time a user checks a radio button. This is how my HTML looks like. onclick="change()" to actually call your function. But you should change it to onclick="change(this);" to pass a reference to the clicked button to your function, then:

functionchange(el){
    $("#ZAAL_NAME").val(el.value) ;
}

Also you jQuery selector need a # to select by id.

Better though would be to remove the inline onclick from your markup and do it like this:

$('input[name="zaal_ID"]').click(function() {
    $('#ZAAL_NAME').val(this.value);
});

The latter would need to be in a document ready handler and/or in a script block that appears after your radio buttons in the page source.

Note: when getting the value of the clicked element you can say $(el).val() or $(this).val() (depending on which of the two functions you are looking at), but given that el and this are references to the DOM element you can just get its value property directly with el.value or this.value.

Solution 2:

$('input[name="zaal_ID"]').change(function(){
   $('#ZAAL_NAME').val( this.value );
})

Solution 3:

functionchange(){
   $("ZAAL_NAME").val( $(this).val() ) ;
}

or

functionchange(){
   $("ZAAL_NAME").val($("input[type='radio']:checked").val()) ;
}

Solution 4:

try -

$(':radio').change(function(){
   $('#ZAAL_NAME').val($(this).val());
})

Demo: http://jsfiddle.net/KMXnR/

Solution 5:

use onclick="change(this.value);" and the function use like this

functionchange(e){
    $("ZAAL_NAME").val(e) ;


}

Post a Comment for "Change A Hidden Input Fields Value When A Radio Button Is Selected"