0

Hi been wrestling this form and the last step (actually submitting) has me scratching my head. What I have so far is the form:

<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">

and a script that checks the age and sets a cookie/changes display

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;
    }}

that all seems to be working well.. just missing kind of a crucial step of actually submitting the form if it validates (if they pass the age question). So I am thinking that this will be wrapped in that script.. something in here :

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

Can someone please help me figure out how I could handle this submit?

2
  • You really should use parseInt(number, 10) instead of just parseInt(number) - Otherwise starting your number with a 0 will end up parsing as base 8. 08 and 09 will be undefined Commented Apr 30, 2010 at 18:13
  • thanks but I am not sure what you are talking about.. where do you see parseInt(number) ? Commented Apr 30, 2010 at 20:18

1 Answer 1

2

You would call

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

And that would post the data to the server.

Sign up to request clarification or add additional context in comments.

4 Comments

sorry for being dense but would this submit only if the checkAge returned true? Do I still just attach the action to the form like normal?
@zac - You should put it with the "validated" portion of code (which you correctly identified in your OP), on success - submit the form.
so this should work?? it cant be that easy :P else { var form = document.getElementById('theForm'); if(form != null) form.submit(); createCookie('age','over13',0) return true; } and this <form id="theForm" method='post' action="whatcounts.com/bin/listctrl" name="emailForm">
Well, you would want to put whatever code you wanted to execute before the call to form.submit(), because once that happens, the browser is going to take over and begin getting the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.