Hopefully this e-mail's format doesn't get butchered too badly, but here's a function that walks down a DOM tree looking for a Node with specific attribute value:
/** * startNode is the node to start searching from * criteria is the attribute name * value is the attribute value * ** isIE is a global variable that says whether or not IE is being used. ** IE has non-standard ... */ NodeUtils.getNode = function (startNode, criteria, value) { if (startNode.nodeType == Node.ELEMENT_NODE) { var attr = null; if (isIE && criteria == "class") { // try class attr = startNode.attributes["class"]; if (attr == null) { // try className attr = startNode.attributes["className"]; } } else { attr = startNode.attributes[criteria]; } if (attr != null) { if (isIE && startNode.nodeName == "FORM" && criteria == "name"){ if (startNode.attributes['name'].nodeValue == value) { return startNode; } } else { var attributes = attr.nodeValue.split(" "); for (var i = 0; i < attributes.length; i++) { if (attributes[i] == value) { return startNode; } } } } } // Iterate children. var children = startNode.childNodes; for (var i = 0; i < children.length; i++) { // Check this child node to see if it meets the criteria var childSearch = NodeUtils.getNode(children[i], criteria, value); if (childSearch != null) { return childSearch; } } } So, with this function you could do something like: var myForm = NodeUtils.getNode(document.documentElement, "name", "myForm"); or var myForm = NodeUtils.getNode(document.getElementById("formDiv"), "name", "myForm"); - Dave > -----Original Message----- > From: Arash Bijanzadeh [mailto:[EMAIL PROTECTED] > Sent: Sunday, June 26, 2005 5:00 AM > To: Struts Users Mailing List > Subject: javascript html:fprm and getElementById > > Hi, > I need to change the action of my form on the fly. I use the following > javascript: > function setParam(mode) > { > document.getElementById("myform").action ="<%=(String) > request.getAttribute("origin")%>" > + mode+ ".do"; > document.forms[0].submit(); > > } > and my form is : > <html:form action="<%=(String) request.getAttribute("origin")%>" > styleId="myform" > > > It works perfect under mozilla but not IE. I think the problem is that IE > looks for Id in the name field of form and he couln't find it. > Could anyone help me? > Regards > ARash --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]