2016-01-13 30 views
-1

我想在客戶端存儲一些數據,以便創建一個JavaScript代碼,但是在表單提交之後,我得到空的隱藏字段值。如何解決這個問題?表單提交後獲取空的隱藏值

fid = 1100124686694263; 
 
user = Akshay Barpute; 
 
document.getElementById('fid1').value = fid; 
 
document.getElementById('user1').value = user;
Welcome Fill below information to setup your account</br> 
 
<form action='fb1.php' method='post'> 
 
    Enter your email: 
 
    <input type='email' name='emailid'> 
 
    </br> 
 
    Select examination: 
 
    <input type='radio' name='jungle' value='GRE'>GRE& nbsp;&nbsp;&nbsp;&nbsp; 
 
    <input type='radio' name='jungle' value='GMAT'>GMAT&nbsp;&nbsp;&nbsp;&nbsp; 
 
    <input type='radio' name='jungle' value='CAD'>CAD&nbsp;&nbsp;&nbsp;&nbsp; 
 
    <input type='radio' name='jungle' value='MBA CET'>MBA CET&nbsp;&nbsp;&nbsp;&nbsp; 
 
    <input type='radio' name='jungle' value='others'>others(includes bank & it company exams) 
 
    <br> 
 
    <input type='hidden' name='fid' id='fid1' value=''> 
 
    <input type='hidden' name='user' id='user1' value=''> 
 
    <input type='submit' name='sub' value='Submit'> 
 
</form>

+3

''
???無論如何,'user = Akshay Barpute;'是無效的JavaScript,所以它沒有運行,所以你得到空值。下次檢查控制檯。 –

+0

此外,無關,但嘗試使用' '而不是重複' 's,你可能會得到更好的結果。 –

+0

謝謝!這解決了問題。 –

回答

1

可變user需要字符串類型:

fid = 1100124686694263; 
user = "Akshay Barpute"; 
document.getElementById('fid1').value = fid; 
document.getElementById('user1').value = user;