Jump to content

Mandatory Fields Script - Not Working


Guest Yamen Rock
 Share

Recommended Posts

Guest Yamen Rock

I've got a form in a website and I wanted to maker the fields mandatory so I added to the html header (see below)unfortunately whehn some fields are not filled no alert is shown.what should i do? (answer me ASAP)Thanks, Yamenrheader:<script>function TestDataCheck(){ var name = document.frm.contact.value; var email = document.frm.email.value; var phone = document.frm.phone1.value; var course = document.frm.course2.value;; if ( (name==null || name=="") || (email==null || email=="") || (phone==null || phone=="") || (course==null || course=="")) { alert("Please fill all fields."); return false; } return true;}</SCRIPT>body:<form onsubmit="return TestDataCheck();" action="http://MYWEBSITE/contact/recognize.asp" id="frm" method="post"> <!-- <form action="http://MY_WEBSITE/contact/recognize.asp" id="frm" method="post">--> <SELECT size="1" name="course1" style="border:1px solid #FFFFFF; font-family: Arial; color: #FFFFFF; font-weight: bold; position:absolute; left:33; top:24; background-color:#FFFFFF"> <option>ג'ון ברייס נצרת</option>

Link to comment
Share on other sites

Hi,here is what i think you should have:

function TestDataCheck(){var name = document.getElementById('frm').contact.value;var email = document.getElementById('frm').email.value;var phone = document.getElementById('frm').phone1.value;var course = document.getElementById('frm').course2.value;

I think this may work however it may not, if not then try:

function TestDataCheck(){var name = document.getElementById(contact).value;var email = document.getElementById(email).value;var phone = document.getElementById(phone1).value;var course = document.getElementById(course2).value;

Link to comment
Share on other sites

Sort of close. Give your elements IDs and get the values from those.<SELECT size="1" name="course1" id="course1" ...var course1 = document.getElementById("course1").value;Make sure to put the IDs in quotes.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...