Jump to content

validation - to ensure at least one field is filled [incl - combos/dropdowns]


chet139

Recommended Posts

Hey all,

 

I have basic searc forms however I need to ensure that at least one field is filled in. This could include the one field has being a dropdown menu.

 

Any help is appreciated as I am at a lost with this. I got some code which does what I need but it ignores the dropdowns - I have tried amending code but have had no success.  As you may have gathered I am quite new to this.

 

Here is the code: (but feel free to post something else which maybe simplier that I can use.)

 

<script type="text/javascript">

function validateAdvSearch() //Validation to ensure that a blank form is not submitted.

{

var f = document.forms[0];

var num = f.elements.length;

var j = 0;

for (var i=0; i<num; i++)

{

if (f.elements.type == 'text') { if (f.elements.value) { j = j+1; } }

else { continue; }

}

if (j == 0) { alert('Please Enter at least One Search Criteria'); return false; }

}

</script>

All,

 

I think I may have solved this. Please add comments to my solution.

 

<script type="text/javascript">
	function checkFields() {
	if(user.userId.value != "" || user.userTitle.value != "" || user.userFirstname.value != "" || user.userLastname.value != "" || user.userType.value != "") 
	{
	alert("Validation OK"); // Success Code goes here
	return true;
	}

	else {
	alert("Please Provide Minimum of One Search Criteria");
	return false;
	}
	}

</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.