表单在javascript中提交

时间:2010-04-30 17:58:22

标签: javascript forms-authentication

你一直在摔跤这个表格,最后一步(实际提交)让我摸不着头脑。我到目前为止的形式是:

<form id="theForm"  method='post' name="emailForm">
<table border="0" cellspacing="2">
<td>Email <span class="red">*</span></td><td><input type='text'class="validate[required,custom[email]]" size="30"></td></tr>
<td>First Name:</td><td><input type='text' name='email[first]' id='first_name' size=30></td></tr>
<tr height="30">
<td  cellpadding="4">Last Name:</td><td><input type='text' name='email[last]' id='e_last_name' size=30>
<td>Birthday</td>
<td><select name='month' style='width:70px; margin-right: 10px'>
<option value=''>Month</option>
<option value="1">Jan</option>
<option value="2">Feb</option>

....

</select><select name='day' style='width:55px; margin-right: 10px'>
<option value=''>Day</option>

<option value="1">1</option>
<option value="2">2</option>
...

<option value="31">31</option>
</select><select name='year' style='width:60px;' >
<option value=''>Year</option>

<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
...
</select>

<input type='image' src='{{skin url=""}}images/email/signUpButt.gif' value='Submit' onClick="return checkAge()" />
<input type="hidden" id= "under13" name="under13" value="No">

和一个检查年龄并设置cookie /更改显示的脚本

function checkAge()
{

var min_age = 13;
var year = parseInt(document.forms["emailForm"]["year"].value);
var month = parseInt(document.forms["emailForm"]["month"].value) - 1;
var day = parseInt(document.forms["emailForm"]["day"].value);
var theirDate = new Date((year + min_age), month, day);
var today = new Date;

if ( (today.getTime() - theirDate.getTime()) < 0) {

var el = document.getElementById('emailBox');
if(el){
el.className += el.className ? ' youngOne' : 'youngOne';
}
document.getElementById('emailBox').innerHTML = "<style type=\"text/css\">.formError {display:none}</style><p>Good Bye</p><p>You must be 13 years of age to sign up.</p>"; 
createCookie('age','not13',0)
return false;
}
else {

createCookie('age','over13',0)
return true;
    }}

所有人似乎都运作良好..如果它确认了(如果他们通过年龄问题),那么实际提交表格的关键步骤就会丢失。所以我认为这将包含在那个脚本中..这里有一些东西:

else {
createCookie('age','over13',0)
return true;
}

有人可以帮我弄清楚如何处理这个提交吗?

1 个答案:

答案 0 :(得分:2)

你会打电话给

var form = document.getElementById('theForm');
if(form != null)
   form.submit();

这会将数据发布到服务器。