vj5 Posted March 25, 2008 Share Posted March 25, 2008 I have two fields start date and end date. If the start date is empty, user cannot enter the end date. In otherwords, if there is an end date, there should be a start date. how will I validate in javascript. Please help. Link to comment Share on other sites More sharing options...
vj5 Posted March 25, 2008 Author Share Posted March 25, 2008 I tried doing like this. It works, but after I enter the data, it is still showing the alert sign to enter data. <script language="JavaScript" type="text/javascript"><!--function checkform ( form ){ // ** START ** if (form.dosend.value != "") { alert( "Please enter Start Date." ); return false; } // ** END ** return true;}//--></script> Link to comment Share on other sites More sharing options...
jesh Posted March 25, 2008 Share Posted March 25, 2008 This could be one way of doing it: <html><body><script type="text/javascript">function enable(ele, id){ if(ele.value != "") { document.getElementById(id).disabled = false; } else { document.getElementById(id).disabled = true; }}</script><input type="text" id="start" onkeyup="enable(this, 'end');" /><input type="text" id="end" disabled="disabled" /></body></html> Link to comment Share on other sites More sharing options...
Jesdisciple Posted March 25, 2008 Share Posted March 25, 2008 Note that you should also validate on the server-side, for two reasons: JavaScript can't deliver security, because it's managed by the browser. All the currently available browsers assist the user in whatever task they are attempting. If your user is your friend, the browser is too; if the user is a hacker, the browser is a hacking tool. JavaScript can't be dependable, because browsers vary in their support for it, and some don't support it at all. For example, the text-based browser Lynx is oblivious to all JavaScript and would submit invalid data. Link to comment Share on other sites More sharing options...
vj5 Posted March 26, 2008 Author Share Posted March 26, 2008 Thank you all for your input. I finally did validation in PHP . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.