Guest Yamen Rock Posted June 28, 2009 Share Posted June 28, 2009 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 More sharing options...
duncan_cowan Posted June 29, 2009 Share Posted June 29, 2009 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 More sharing options...
justsomeguy Posted June 29, 2009 Share Posted June 29, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.