Question

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?

Was it helpful?

Solution

Simple:

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

OTHER TIPS

Try,

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

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

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

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

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

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top