Jump to content

[SOLVED] Validation help and another problem


xoligy

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.