2016-01-13 47 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;