简体   繁体   中英

How to set a value of one hidden field to another hidden field using jQuery?

I'm using PHP, Smarty, jQuery(jquery-1.7.1.min.js), AJAX, etc. Following is my HTML code:

<input type="hidden" id="que_id" name="que_id" value=76539 />

I'm having another input of type hidden as follows:

<input type="text" name="question_id" id="question_id" value=""/>

Now what I want to achieve is when the page loads completely, set the value of first input hidden field to the second hidden input field. How should I do this?

Simple:

$(document).ready(function() {
    $("#question_id").val($("#que_id").val());
});

Try,

$(document).ready(function(){
  $(window).load(function(){
    $('#question_id').val($('#que_id').val());
  });
});
var first_hidden_Value = $('#que_id').val();

$('#question_id').val(first_hidden_Value);

You have to do this in document.ready() ;

It's very simple. try this code:

$(function(){//ensure document is ready 
  $('#question_id').val($('#que_id').val());
});

Within your document ready, you can just grab the element using the ID selector and just use the .val() method, which can both return and set the value.

$(document).ready(function(){
    $('#question_id').val( $('#que_id').val() );
});

put this code in header tag

$( document ).ready(function() {
var a = $('#que_id').val();
 $('#question_id').val(a);
});
$(function(){

    var hidden1 = $('#que_id').val();

    $('#question_id').val(hidden1);

});

User this code

    $(document).ready(function(){
    var que_id = $('#que_id').val(); 
    $('#question_id').val(que_id);

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM