0
votes

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?

8

8 Answers

5
votes

Simple:

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

Try,

$(document).ready(function(){
  $(window).load(function(){
    $('#question_id').val($('#que_id').val());
  });
});
1
votes

It's very simple. try this code:

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

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() );
});
1
votes
var first_hidden_Value = $('#que_id').val();

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

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

1
votes

put this code in header tag

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

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

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

});
0
votes

User this code

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

});