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 pletely, set the value of first input hidden field to the second hidden input field. How should I do this?
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 pletely, set the value of first input hidden field to the second hidden input field. How should I do this?
Share Improve this question edited Jan 5, 2016 at 8:18 halfer 20.3k19 gold badges109 silver badges202 bronze badges asked Mar 6, 2014 at 4:51 PHPLoverPHPLover 13k51 gold badges172 silver badges321 bronze badges8 Answers
Reset to default 5Simple:
$(document).ready(function() {
$("#question_id").val($("#que_id").val());
});
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);
});