Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

netscape 7 compliant javascript??

Status
Not open for further replies.

jdt141

IS-IT--Management
Jan 27, 2004
10
US
The following code works great in IE, but I can't get it to work in netscape 7....

I get a "document.forms has no properties" error from the netscape js console.... I've been pounding my head on this one for awhile... help!!

function checkForm( )
{
var f = document.forms[0];
for ( var i = 0; i < f.elements.length; i++ )
{
//clipped...
//performing stuff on f.elements
}
}
 
Very probably: HTML code contains no <FORM> ... </FORM> tags. Netscape is a little bit strict here, IE attempts to be smart as usual.
 
well.... i thought that too - but the script is embedded in a file and being downloaded from the header... actually i'm dynamically creating the forms with XML and an XSL stylesheet... everything works great in IE.... but the calling code would be

<form name="f" method="post" action="actionPg.cfm" onSubmit="return checkForm()">
 
Maybe this?

Code:
<form name="f" method="post" action="actionPg.cfm" onSubmit="return checkForm([COLOR=red]this[/color])">

There's always a better way. The fun is trying to find it!
 
no dice... and it shouldn't matter... as document.forms[0], when assigned on the second line of code should assign "f" to the DOM part underneath document.forms[0].... it does, however, still work in IE...

::hates netscape::
::pulls out hair::
 
OK... copy&paste view source, strip unnecessary details and post code here.
 

>> i'm dynamically creating the forms

Are you attempting to access form[0] before the form has been dynamically created? Does NN7 even support XML / XSL dynamic form creation?

Dan
 
Here's the javascript:

Code:
// JavaScript Document
function checkForm(  ) 
{ 	
	var f = form;
	var objTemp; 
	var strName = ''
	var boolIsValid = true;
	for ( var i = 0; i < f.elements.length; i++ ) 
	{
		objTemp = f.elements[i];
		strName = objTemp.name
                //snipped
		if ( strName.substr(strName.length - 4 ) == '_req' ) 
		{
			//strName = 
			// strName.replace( /data_/, '' );
			strName = strName.replace( /_req/, '' );
			strName = strName.replace( /_/g, ' ' );
			strName = strName.toLowerCase();
			//alert(strName);
			if ( objTemp.value == '' ) 
			{ //snipped

				}
			else if ( objTemp.type == 'radio' ) 
			{			
			//snippped
			}
			if(boolIsValid == false)
				break;
		}
		if (strName.substr(strName.length - 4 ) == '_opt' )
		{
			if(f.elements[i-1].checked && objTemp.value == '')
			{//snipped
			}
		}
	}
	if ( boolIsValid == true ) 
	{
		return true;
	} 
	else 
	{
  		alert( strMessage );
		return false;
	}
}

here's the start of the XSL sheet:

Code:
 <?xml version="1.0"?>
<!-- XSL Stylesheet that generates the surveys-->


<xsl:stylesheet version="1.0"
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]


<xsl:template match="/">
  <html>
  <head>
	<script language="JavaScript" src="validateXML.js" type="text/JavaScript"></script>
  </head>
  <body>
  <h2><xsl:value-of select="survey/sname"/></h2>
	<table border = "0" width ="600">
		<tr>
			<td>Survey Directions: <xsl:value-of select="survey/directions"/></td>
			<td>SurveyID: <xsl:value-of select="survey/survID"/></td>
		</tr>
	</table>
	<form name="form" method="post" action="[URL unfurl="true"]http://damidb06/appsa/Justin/Test/takeResults.cfm"[/URL] onSubmit="return checkForm()">

As for the "supporting dynamic forms" I cannot answer that. All I'm doing is an XSLT transformation. The form DOES appear in netscape. It all looks fine, i just can't get the script to execute. It does work in IE, however...

Thanks for any help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top