In order to validate that all of teh items on my page have been filled out correctly I use these functions:
function check_form( form )
{
var required_fields = check_fields( form );
if ( required_fields > 0 )
{
alert("Please complete all fields with red labels.");
return false;
}
return true;
}
/*
Check each of the entries for valid input.
Returns the number of required fields left to fill in.
*/
function check_fields( form )
{
var need_input = 0;
alert("hey");
need_input += checkForNull( form.types, 'type_lbl');
need_input += checkForNull( form.severity, 'severity_lbl');
need_input += checkForNull( form.parent_system, 'par_lbl');
need_input += checkForNull( form.system, 'sys_lbl');
need_input += checkForNull( form.headline, 'head_lbl');
need_input += checkForNull( form.description, 'desc_lbl');
alert("again");
return need_input;
}
/*
When an element is changed, if it is a valid value, decrement the number
or required fields.
When an element is changed, if it is not a valid value, increment the number
or required fields.
*/
function checkForNull( element, id )
{
var label = document.getElementById( id );
alert("hmm");
if ( element.value == "NULL" || element.value.replace(/\s*$/, '') == "" )
{
label.className = "incomplete";
return 1;
}
label.className = "complete";
return 0;
}
The problem right now is that with the alerts to test the form it is never fireing alert("again") and I don't see a reason why it is not. Also I have found that though it will fire alert("hmm") when I move it into the if statement it stops firing it.
I can even submit my form without filling in anything and it does not alert that I need to fill in all of the elements. Does anyone have any ideas?
Thanks in advance,
Xana
If history is to change let it change. If the world is to be destroyed so be it. If it is my fate to die ... I must simply laugh.