Jump to content

Mandatory Fields Script - Not Working


Guest Yamen Rock

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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...