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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Body Onload not working 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
Does anyone have a suggestion why the script version work and the body onload method doesn't?

Thanks
Lyndon

Code:
<!--- This works --->
<script>
	document.LicenseNameString.NameString.focus();
</script>

<!--- This doesn't work --->
<body onload="document.LicenseNameString.NameString.focus()">
 
That should work no problem - there's probably something else to it that you're not showing us. For example, copy/paste this into a new HTML file and it will work fine:
Code:
<body onload="document.forms['LicenseNameString'].elements['NameString'].focus()">

<form id="LicenseNameString">
<input type="text" name="NameString" />
</form>

</body>

Hmm.... I just remembered. Double check to ensure that you don't have any other onload functions defined on the page. If you have any javascript on the page anywhere that looks like this:
Code:
window.onload = someFunction;
then they will not both work. I can't remember which one fails (probably the one defined in the body tag). If that is your problem, then all you need to do is combine the 2 onload calls to one function.

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
that will be the javascript you meant to post in then.

I ment to post here as I wanted to use the html method, which doesn't work. I included the javascript method, as a clue, because it does work.

Dan, I tried your suggestion; no luck.
Code:
<body onload="document.forms['LicenseNameString'].elements['NameString'].focus();">

I don't think there is any other onload event going on....
But it is a Coldfusion server...

Here is the form code:
Code:
<HTML>
<HEAD><TITLE>Track Maintained License Data</TITLE></HEAD>
<body onload="document.forms['LicenseNameString'].elements['NameString'].focus();">
<br>
<div align="center" >
	<table border="0">
		<cfoutput>
			<td valign="top" nowrap>
				<form action="RemLicNameString.cfm" method="POST" name="LicenseNameString">
					<input size="15" maxlength="50" type="Text" name="NameString">
					<input type="submit" value="Name Search">
				</form>
			</td>
			<td valign="top" nowrap>
				<a class="special" href='RemLicSearch.cfm?alphaindex=All' title='List all license records' style="font-size: 75% ;"> All</a>|
				<cfloop from="65" to="90" step="1" index="theCharacter">
					<a class="special" href='RemLicSearch.cfm?alphaindex=#Chr(theCharacter)#' title='List all license records where name begins with "#Chr(theCharacter)#"' style="font-size: 75% ;"> #Chr(theCharacter)# </a>|
				</cfloop>
			</td>
		</cfoutput>
	</table>
</div>


 
Copy/Pasting exactly what you posted above into a new HTML file works fine. There has to be something else you're not showing. Can you post the entire page, or a link to the page?

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Here you go kaht:

Code:
<cfparam name="Session.NameString" default="">
<cfparam name="AlphaIndex" default="">
<CFQUERY NAME="RP" DATASOURCE="NEWtrackdata">
    SELECT *
	FROM LICENSE
	<cfif isdefined("mtrack")>
		where track = '#mtrack#'
	<cfelse>
		<cfif isdefined("mtype")>
			where type = '#mtype#'
		<cfelse>
			<cfif isdefined("mdate")>
				where lic_date=#createodbcdate(mdate)#
			<cfelse>
				<cfif Trim(Session.NameString) gt ''>
					WHERE NAME LIKE '%#Session.NameString#%'
				<cfelse>
					<cfif '#AlphaIndex#' EQ 'All'>
						<!--- No condition to pass --->
					<cfelse>
						WHERE NAME LIKE '#AlphaIndex#%'	
					</cfif>
				</cfif>
			</cfif>
		</cfif>
	</cfif>
	ORDER by Name
</CFQUERY>
<HTML>
<HEAD><TITLE>Track Maintained License Data</TITLE></HEAD>
<body onload="document.forms['LicenseNameString'].elements['NameString'].focus();">
<br>
<div align="center" >
	<table border="0">
		<cfoutput>
			<td valign="top" nowrap>
				<form action="RemLicNameString.cfm" method="POST" name="LicenseNameString">
					<input size="15" maxlength="50" type="Text" name="NameString">
					<input type="submit" value="Name Search">
				</form>
			</td>
			<td valign="top" nowrap>
				<a class="special" href='RemLicSearch.cfm?alphaindex=All' title='List all license records' style="font-size: 75% ;"> All</a>|
				<cfloop from="65" to="90" step="1" index="theCharacter">
					<a class="special" href='RemLicSearch.cfm?alphaindex=#Chr(theCharacter)#' title='List all license records where name begins with "#Chr(theCharacter)#"' style="font-size: 75% ;"> #Chr(theCharacter)# </a>|
				</cfloop>
			</td>
		</cfoutput>
	</table>
</div>
<cfif #rp.RecordCount# is 0>
	<div align="center" class="PageTitle">No Licenses found that begins with "<cfoutput>#AlphaIndex##Session.NameString#</cfoutput>", try another Letter.</div>
<cfelse>
	<cfif isdefined("mtrack")>
		<div align="center" class="PageTitle">Track Maintained License Data Where Track is <cfoutput>"#mtrack#" (Records Found: #NumberFormat(rp.RecordCount)#)</cfoutput></div>
	<cfelse>
		<cfif isdefined("mtype")>
			<div align="center" class="PageTitle">Track Maintained License Data Where License Type Is <cfoutput>"#mtype#" (Records Found: #NumberFormat(rp.RecordCount)#)</cfoutput></div>
		<cfelse>
			<cfif isdefined("mdate")>
				<div align="center" class="PageTitle">Track Maintained License Data Where Date Licensed Is <cfoutput>"#DateFormat(mdate,'mm/dd/yyyy')#" (Records Found: #NumberFormat(rp.RecordCount)#)</cfoutput></div>
			<cfelse>
				<cfif Trim(Session.NameString) gt ''>
					<div align="center" class="PageTitle">Track Maintained License Data Where Name Contains <cfoutput>"#Session.NameString#" (Records Found: #NumberFormat(rp.RecordCount)#)</cfoutput></div>
				<cfelse>
					<div align="center" class="PageTitle">Track Maintained License Data Where Name Begins With <cfoutput>"#AlphaIndex#" (Records Found: #NumberFormat(rp.RecordCount)#)</cfoutput></div>
				</cfif>
			</cfif>
		</cfif>
	</cfif>
	<cfset Session.NameString=''>
	<TABLE class="BinkleyTable" width="100%">
		<TR>
			<TH class="ColumnHeadingCell">Pend</Th>
			<TH class="ColumnHeadingCell">Track</Th>
	    	<TH class="ColumnHeadingCell">Name</Th>
	    	<TH class="ColumnHeadingCell">Type</Th>
		    <TH class="ColumnHeadingCell">City State</Th>
    		<TH class="ColumnHeadingCell">License Date</Th>
			<TH class="ColumnHeadingCell">Comments</Th>
		</TR>
		<CFOUTPUT query="RP">
			<TR>
				<td class="NormalCell">
					<a href="LicEditMenu.cfm?row=#rp.index#&alphaindex=#alphaindex#&mssn=#rp.ssn#" onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="color: dodgerblue; font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">Yes</div>
						<cfelse>
							No
						</cfif>
					</a>
				</TD>
				<td>
					<a	class="special" 
						href="RemLicSearch.cfm?mtrack=#rp.track#&alphaindex=#alphaindex#&mssn=#rp.ssn#" 
						title="List all license records where track code is #rp.track#"
						 onmouseover="return escape('Some text')"
						 style="font-size: 90% ;">
						 <cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#Track#
					</a>
				</TD>
				<td class="NormalCell">
					<a href="LicEditMenu.cfm?row=#rp.index#&alphaindex=#alphaindex#&mssn=#rp.ssn#" onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="color: dodgerblue; font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#name#
					</a>
				</TD>
				<td>
					<a class="special" href="RemLicSearch.cfm?mtype=#rp.type#&alphaindex=#alphaindex#&mssn=#rp.ssn#" title="List all license records where license type is #rp.type#" onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#Type#
					</a>
				</TD>
				<td class="NormalCell">
					<a href="LicEditMenu.cfm?row=#rp.index#&alphaindex=#alphaindex#&mssn=#rp.ssn#" onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="color: dodgerblue; font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#CITY_STATE#
					</a>
				</TD>
				<td>
					<a class="special" href="RemLicSearch.cfm?mdate=#rp.lic_date#&alphaindex=#alphaindex#&mssn=#rp.ssn#" title="List all license records where license date is #DateFormat(rp.lic_date,'mm/dd/yyyy')#"  onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#dateformat(LIC_DATE,"MM/DD/YYYY")#
					</a>
				</TD>
				<td>
					<a href="LicEditMenu.cfm?row=#rp.index#&alphaindex=#alphaindex#&mssn=#rp.ssn#" onMouseOver="highlight(this)" onMouseOut="noHighlight(this)" style="color: dodgerblue; font-size: 90% ;">
						<cfif rp.Pending eq 1>
							<div style="color: red;">
						</cfif>
						#COMMENTS#
					</a>
				</TD>
			</TR>
		</CFOUTPUT>
	</TABLE>
</cfif>
<!--- This Works --->
<!--- <script>
	document.LicenseNameString.NameString.focus();
</script> --->
</body>
</html>
 
I hate to keep asking you to post more code, but can you show the HTML rendered from this code? Load your page in a browser and do a view-source of the page.

The code you posted above has a bunch of coldfusion tags in it and I don't know how to program in coldfusion. Posting only what the browser sees (the view-source) will help us determine why the browser is behaving incorrectly.

In the meantime I can browse thru what you posted and I might be able to spot something.

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
My fault kaht...

I didn't catch what you ment, I saw the browser source and the problem was right in there.

I have a javascript menu on all my pages.

Thanks
Lyndon
 
So it was a case of window.onload overwriting it?

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Yes, that meun load on every page of my application folder from a server side script.

I forgot about it.

Sorry to bother.

Lyndon
 
That's cool, at least it was easy to identify [thumbsup2]

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top