2012-05-04 2 views
0

Попытка создать форму, которая заставит людей установить флажок с фразой «Я принимаю условия», чтобы отправить форму.Необходимо установить флажок для отправки формы

Это то, что у меня есть, но оно не отправляет форму - я получаю сообщение об ошибке.

Javascript, что я поместил в заголовке:

<script type="text/javascript"> 
    <!-- 

    function validate_form () 
    { 
    valid = true; 

    if (document.form1.cb.checked == false) 
    { 
    alert ("Please check the Terms & Conditions box ."); 
    valid = false; 
    } 

    return valid; 
    } 

    //--> 
    </script> 

Форма:

<form action="/cgi-bin/FormMail.pl" method="POST" name="frmOne" id="frmOne"> 
    <input type=hidden name="recipient" value="[email protected]"/> 
    <table width="100%" cellspacing="5" cellpadding="5" style="margin-top:-20px"> 
    <tr> 
    <td width="50%" valign="top"> 
    <br/> 
     <p><span id="sprytextfield1"> 
    <label for="Full Name">Full Name (First and Last): </label> 
    <input name="Full Name" type="text" id="name" tabindex="10" size="60" /> 
    <span class="textfieldRequiredMsg"><br />Please provide information.</span></span> </p> 
    <p><span id="sprytextfield2"> 
    <label for="Your Email">Your e-mail address: </label> 
    <input name="email" type="text" id="email" size="60" /> 
    <span class="textfieldInvalidFormatMsg"></span></span> </p> 
    <p><span id="sprytextfield3"> 
    <label for="Phone Number"> Phone Number: </label> 
    <input name="Phone Number" type="text" id="phone" size="60" /> 
    <span class="textfieldInvalidFormatMsg"><br />Invalid format.</span><span class="textfieldRequiredMsg"><br/>A phone number is required.</span></span></p> 
    <p class="text"> 
     <span id="sprytextfield4"> 
    <label for="Nature Of The Accident">Nature of Accident, i.e. slip and fall, motor vehicle accident, etc.: </label> 
    <input name="Nature Of The Accident" type="text" id="natureOfAccident" size="60" /> 
    </span></p> 
    <p><span id="sprytextfield5"> 
    <label for="Date Of The Accident">Date of the Accident: </label> 
    <input name="Date Of The Accident" type="text" id="dateOfAccident" size="60" /> 
    <span class="textfieldRequiredMsg"><br />Please provide information.</span><span class="textfieldInvalidFormatMsg"><br />Invalid format.</span></span></p> 
    <p class="text"> 
    </td> 

    <td width="50%" valign="top"> 

    <p class="text"> 
    <span id="sprytextarea1"> 
    <label for="Description Of The Injury"><br />Brief Description of your Injuries: </label> 
    <textarea name="Description Of The Injury" cols="45" rows="4" id="descriptionOfInjury"> 
    </textarea> 
    <span class="textareaRequiredMsg"><br />Please provide information.</span></span></p> 
    <p class="text"> 
    <span id="sprytextarea2"> 
    <label for="Description Of The Accident">Brief Description of the Accident:</label> 
    <textarea name="Description Of The Accident" id="descriptionOfAccident" cols="45" rows="4"></textarea> 
    <span class="textareaRequiredMsg"><br /> 
    Please provide information.</span></span></p> 
    <p class="text"> 
    <span id="sprytextfield6"> 
    <label for="How Did You Hear About Us">How did you hear about us?: </label> 
    <input name="How Did You Hear About Us" type="text" id="howDidYouHear" size="56" /> 
    <span class="textfieldRequiredMsg"><br />Please provide information.</span></span> </p> 
    <input type="checkbox" name="agree" value="agree_terms" id="disclaimer" /> 
    <label for="disclaimer">I have read the Disclaimer</label> 
    <br/><br /> 
    &nbsp;<input type="reset" name="reset" id="reset" value="Reset Form" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <input type="submit" name="Form Action" id="send" tabindex="100" value="Submit" /> 

    </td> 
    </tr> 
    </table> 

</form> 
<script type="text/javascript"> 
<!-- 
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur", "change"]}); 
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email", {validateOn:["blur", "change"], isRequired:false}); 
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "phone_number", {validateOn:["blur"], useCharacterMasking:true}); 
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none", {isRequired:false, validateOn:["blur", "change"]}); 
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "date", {hint:"dd/mm/yyyy", validateOn:["blur", "change"], format:"dd/mm/yyyy"}); 
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1", {validateOn:["blur", "change"]}); 
var sprytextarea2 = new Spry.Widget.ValidationTextarea("sprytextarea2", {validateOn:["blur", "change"]}); 
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "none", {validateOn:["blur", "change"], hint:"Google, etc"}); 
//--> 
</script></div> 
+0

я могу видеть, ни '' form1' ни cb' элементы. – sp00m

ответ

0

Изменение <form action="/cgi-bin/FormMail.pl" method="POST" name="frmOne" id="frmOne"> в <form action="/cgi-bin/FormMail.pl" method="POST" name="frmOne" id="frmOne" onSubmit="validate_form();">

Какие ошибки вы получаете?

и изменить document.form1.cb.checked к document.frmOne.agree.checked

+0

Изменения работают до степени, когда форма теперь скажет мне, что есть ошибка, и мне нужно выбрать, что я прочитал отказ от ответственности. Однако после того, как я нажму «ОК», он все равно перейдет к отправке. – Andrew

+0

Изменить '

' to '' – Bloafer

0

Дайте попробовать с document.getElementById("disclaimer").checked == false.

1

Вы ссылаетесь форму и элементы неправильно, попробуйте что-то вроде этого:

<form name="frmOne" method="POST" onSubmit="return checkForm(frmOne);" action="/cgi-bin/FormMail.pl"> 

<script> 
function checkForm(form) 
{ 
    if(!form.agree.checked) 
    { 
     alert("You must agree to this disclaimer before applying."); 
     return false; 
    } 
} 
</script> 

Я надеюсь, что помог