xoligy Posted September 16, 2008 Share Posted September 16, 2008 Ok i just got this bit of javascript below to check for blank fields and it works! The thing is i need a second volidation but im unsure if i just have to copy the whole code again or just add a second part if thats the case im lost lol! Now the second problem i have is that once the button has been pressed that sends the form the person is unable to press the same button again because of some other code i have inplace which stops that! So how would i get around that? I carnt just remove the other code as its needed :/ <SCRIPT LANGUAGE="JavaScript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") {alert(alerttxt);return false;} else {return true} } } function validate_form(thisform) { with (thisform) { if (validate_required(topic,"You forgot to enter a subject title!")==false) {topic.focus();return false;} } } </script> Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 16, 2008 Share Posted September 16, 2008 Well, you haven't told us how the code that disables the button is executed, so we can't really help you get around it. I would recommend having your validate_form function to disable the button once everything has been validated. Then, if the form doesn't validate, the button will never be disabled. Quote Link to comment Share on other sites More sharing options...
xoligy Posted September 16, 2008 Author Share Posted September 16, 2008 Ive actually found away around the disabling of the button now i';ll just put the code on the apges that its needed so i just need to know how to add an extra validation rule on the js above Quote Link to comment Share on other sites More sharing options...
uniflare Posted September 17, 2008 Share Posted September 17, 2008 To add an extra field to check if its empty, you re-use the existing function call and customize it as you wish: <SCRIPT LANGUAGE="JavaScript"> // This Is The ReUsable Field Checking Function function validate_required(field,alerttxt){ with (field){ if (value==null||value==""){ alert(alerttxt); return false; }else{ return true; } } } // Individual Field Check Block function validate_form(thisform){ with (thisform){ // Check If Topic Is Empty if(validate_required(topic,"You forgot to enter a subject title!")==false){ topic.focus(); return false; } // Check If TopicText Is Empty else if(validate_required(topictext,"You forgot to enter a your topic text!")==false){ topictext.focus(); return false; } // Remember the "Else" on every field you add. } } </script> I have neatened the code so it is easier to read. and added some comments. Although it looks much different i have only added this one block for a field named "topictext": // Check If TopicText Is Empty else if(validate_required(topictext,"You forgot to enter a your topic text!")==false){ topictext.focus(); return false; } // Remember the "Else" on every field you add. Hope this helps. (Im not so good with js so i hope it works lol) Quote Link to comment Share on other sites More sharing options...
xoligy Posted September 17, 2008 Author Share Posted September 17, 2008 Thanks mate and sorry for bugging you on msn Quote Link to comment Share on other sites More sharing options...
uniflare Posted September 17, 2008 Share Posted September 17, 2008 No problem glad i could help Quote Link to comment Share on other sites More sharing options...
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.