General discussion

Locked

Validator Form Works in Firefox but doesn't in IExplorer

By alfonsoarias ·
I have a PHP form callinf a Validator Java Script. It works ok in Mozilla Firefox 1.5.0.9, but does in Internet Explorer 6.0.29
It doesn't recognize any value on the form, then is complaining on the mandatory fields: so looks like Frm.elements[j].value is not valid in Intener Explorer, how I can change this script?
Thanks,

</script>
<script type='text/javascript'>
function formValidator(Frm){
testOk = true;
for (var j=0; j<Frm.elements.length; j++)
{
if (Frm.elements[j].alt)
{
if (Frm.elements[j].name == 'startdate[]' &&
Frm.elements[j].value == "" &&
Frm.elements[j-1].value == "")
{
continue;
}
if (Frm.elements[j].name == 'enddate[]' &&
Frm.elements[j].value == "" &&
Frm.elements[j-2].value == "")
{
continue;
}
if (Frm.elements[j].name == 'clientid[]' &&
Frm.elements[j].value == "")
{
continue;
}
var validateType = Frm.elements[j].alt;
var validateObj = Frm.elements[j];
if (validateType == 'numeric')
{
if (!isNumeric(validateObj)) testOk = false;
}
if (validateType == 'date')
{
if (!isDate(validateObj)) testOk = false;
}
if (!testOk) return false;
}
}
return true;
}
function isNumeric(elem){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert('The Element ' + elem.name + ' has an invalid value:');
elem.focus();
elem.select();
return false;
}
}
function isDate(elem) {
var dt = new Date(elem.value);
if (dt.toString() == 'Invalid Date')
{
alert('The Element ' + elem.name + ' has an invalid value');
elem.focus();
elem.select();
return false;
}
return true;
}
</script>

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Is frm Forms[0]

by Tony Hopkinson In reply to Validator Form Works in F ...

The only thing I could find (I was interested, and had little to do, I know I should get a life )
was this
http://www.wdj.co.uk/articles/dhtml2/dhtml2.html

Seems to be suggesting you need to start at

document.forms to get

documents.forms[f].elements[j]

and that forms[0] by itself is not an object.

If it's right you just need an outer loop to iterate through forms.

so forms[0] and documents.forms[0] are different things. Weird but possibly true.

The other ones I found that might adapt were using collections based on getElemnentsbytagname, which actually might work out a little neater, as in validate each type of form element as opposed to testing the type in a big if statement to see which validation to perform.

Collapse -

Do you know that this "question" belongs in the "Questions" forum?

by deepsand In reply to Validator Form Works in F ...

The "Discussion" forum is for matters of general discussion, not specific problems in search of a solution.

Post problems such as this to the "Question" forum, rather than the "Discussion" forum. There are those who specifically seek out problems in need of a solution, and that's where they go to look for such.

Additionally, the "Question" forum provides for your rating the helpfulness of responses, so that others with the same or similar problem might be able to more easily find a solution.

Back to Browser Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums