javascript - Unable to set val of hidden input field -


i have following code, trying set value of hidden field java script.

<script type="text/javascript" language="javascript"> var currenttime = new date(); var tday=currenttime.getdate(); var tmonth=currenttime.getmonth(); var tyear=currenttime.getfullyear();  $("input[name='tday'").val(tday); $('#tmonth').val(tmonth); $('#tyear').val(tyear); document.getelementbyid('tday').value='213';     </script> <div id="edit_bs" class="edit_bs_st"> <form id='edir_pers' class='edit_pers_css' name='edit_pers' action='edit_pers.php' method='post'>  <input id='tyear' name='tyear'/> <input id='tmonth' type='hidden' name='tmonth'  /> <input id='tday' type='hidden' name='tday' />  <button type="submit">submit</button></from> 

the problem value not being passed 'edit_pers.php' blank. have tried document.getlementid.value set value nothing works. dont know wrong code.

hidden doesn't have it. it's call element bad.

this yours: broken

$("input[name='tday'").val(tday); 

this fixed

$('input[name=tday]').val(tday); 

here's result.

$(document).ready(function () {      var currenttime = new date();    var tday=currenttime.getdate();    $('input[name=tday]').val(tday); }): 

as side note, don't need redundant identifiers in code. i'd go since required have name attribute.

html

<input type='hidden' name='tday' /> 

javascript

 $('input[name=tday]').val(tday); 

http://jsfiddle.net/uh7yn/


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -