The problem that I\'m having is that my code works fine in JavaScript but doesn\'t work correctly in Firefox or safari and wondering why. What I\'m doing is I have a loop going
Try using document.getElementsByTagName, as I believe this is supported across all browsers.
var linkList = document.getElementsByTagName("a");
http://jsfiddle.net/aaronfrost/Xra5y/1/ That has your answer.
I don't know asp tags. I assume req is a attribute so this should do what you asked by only alerting if the attributes are equal to your requirments, I use a shortcut array to hold all the found elements by tag name as James said its more crossbrowser.
var a = [];
a = document.getElementsByTagName("input");
for(var i=0; i < a.length; i++){
if (theForm.elements[i].getAttribute('type')== "text" && theForm.elements[i].getAttribute('req') == "yes" ){
alert("Made it here wtih" + theForm.elements[i])
}
}
You should use var theForm = getElementById("theForm")
instead of calling theForm directly. Only Chrome and IE adds the elements ids to the javascript global scope.
And you should use getAttribute()
to get the value of an attribute because only IE has this shortcut.
Try this example.
Use getAttribute to read the custom attributes. See http://jsfiddle.net/8EWQr/.
So instead of
(theForm.elements[a].type == "text" && theForm.elements[a].req == "yes")
use
(theForm.elements[a].getAttribute('type') == "text" && theForm.elements[a].getAttribute('req') == "yes")