Guest Yamen Rock Posted June 28, 2009 Report 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> Quote Link to post Share on other sites
duncan_cowan 0 Posted June 29, 2009 Report 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; Quote Link to post Share on other sites
justsomeguy 1,135 Posted June 29, 2009 Report Share Posted June 29, 2009 (edited) 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 June 29, 2009 by justsomeguy Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.