www.webdeveloper.com
Results 1 to 6 of 6

Thread: on load for rookies

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    20

    on load for rookies

    I'm trying to learn Javascript. Honestly, I don't know how you guys do it. Anyway, I wanted a little alert box to open when the url is loaded. So I tried a few permutations:

    <script type="text/javscript">
    window.onload=init;
    function init(){
    alert ("This boy is working");
    document.Haskins.sku.focus();
    }
    </script>

    or

    <script type="text/javscript">
    window.onload=function (){
    alert ("This boy is working");
    document.Haskins.sku.focus();
    }
    </script>

    When I type document.Haskins.sku.focus() into the firebug console, it works, so I'm really at a loss here. If you have any suggestions, I'd appreciate it

    p.s. I have onload="" in my body tag. I'm trying to migrate to a better implementation

  2. #2
    Join Date
    Sep 2009
    Location
    USA
    Posts
    34
    Hi,

    Without your full HTML it's hard to tell what the exact error is, so I will give you a few of my best guesses.

    For my first guess, your P.S. is what may hold the key

    Your body tag's onload is probably overwriting your script tag's window.onload event.

    My next guess is that the DOM may not be ready by the time you try to focus. In other words, your document.Haskins.sku doesn't exist yet when you try to focus() on it.

    If this doesn't solve it, see if you can post your complete page including your HTML.

  3. #3
    Join Date
    Oct 2009
    Posts
    20
    This message board is like MrExcel, so I hope I'm doing the right thing with the code tag. I thought about the prior two suggestions. I put my script all the way at the bottom of the screen, after the formation of the form so that it would exist when it runs. I also deleted the onload="" portion of the body tag to see if that was the reason, and it didn't seem to be. Well, anyway, here's the entire code. It's obvious a lot of clean up work is necessary


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head><title>Administration - Catalog</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="http://www.scrapbookingsuppliesrus.com/templates/sbsru/styles/style.css"><link rel="stylesheet" href="http://www.scrapbookingsuppliesrus.com/templates/sbsru/styles/blog.css"> <script src="http://www.scrapbookingsuppliesrus.com/templates/sbsru/scripts/dojo.js" type="text/JavaScript"></script></head> <body bgcolor="#ffffff" link="#0000ff" vlink="#000099" alink="#ff0000"><table width=100%> <tr>  <td class=h1>Catalog</td>  <td align="right" class="topmenu">   <!-- Login Code -->  </td> </tr></table> <hr size="1" color="#366090" /> <p /><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr valign="top">  <td width="10%">    <!-- admin nav -->   <table width="100%" align="center" bgcolor="#4d99e5" cellpadding="1" cellspacing="0" border="0">    <tr>     <td>       <table width="100%" cellpadding="2" cellspacing="0" border="0">       <tr align="center">        <td nowrap="nowrap">		 Admin Navigation        </td>       </tr>       <tr bgcolor="#e5f6ff">        <td>		 <a href="http://www.scrapbookingsuppliesrus.com/?admin">Admin Home</a><br />  		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=account">Accounts</a><br /> 		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=blog">Blogs</a><br />		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog">Catalog</a><br />   		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=events">Events</a><br />   		 <a href="http://www.scrapbookingsuppliesrus.com/admin/forum">Forums</a><br />  		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=links">Links</a><br /> 		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=locations">Locations</a><br />		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=mailing">Mailing</a><br />		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=order">Order</a><br /> 		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=order&layer=promo">Promos</a><br /> 		 <a href="http://www.scrapbookingsuppliesrus.com/?admin=testimonials">Testimonials</a><br /> 		 		 <hr size="1" color="#366090" />		 <a href="http://www.scrapbookingsuppliesrus.com/">Home</a></li>        </td>       </tr>      </table>      </td>    </tr>   </table>     </td>   <td width="15" nowrap="nowrap">  </td>  <td width="100%"> 	<table width="100%" cellspacing="0" cellpadding="0">		<tr>			<td bgcolor="#ffffff">				&nbsp;			</td>									<td bgcolor="#efefef" align="center"><a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog">Browse</a></td>						<td bgcolor="#ffffff">&nbsp;</td>												<td bgcolor="#efefef" align="center"><a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=import_products">Import Products</a></td>						<td bgcolor="#ffffff">&nbsp;</td>												<td bgcolor="#efefef" align="center"><a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=import_descriptions">Import Descriptions</a></td>						<td bgcolor="#ffffff">&nbsp;</td>												<td bgcolor="#efefef" align="center"><a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=import_categories">Import Categories</a></td>						<td bgcolor="#ffffff">&nbsp;</td>												<td bgcolor="#efefef" align="center"><a href="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=import_vendors">Import Vendors</a></td>						<td bgcolor="#ffffff">&nbsp;</td>												<td bgcolor="#4d99e5" align="center">feature_update</td>						<td bgcolor="#ffffff">&nbsp;</td>								</tr>		<tr bgcolor="#4d99e5">			<td colspan="13"></td>		</tr>	</table>	  <h3>Featured product updater for Vivian's feature spotlighting delight.</h3> <table width="538">			<tr>				<td width="25%" align="center">					SKU				</td>				<td width="50%" align="center">					Description				</td>				<td width="vendor" width="25" align="center">					Vendor				</td>			</tr>		 <!--I'm sure we can just use the variable as an array or a number without recasting-->					<tr>				<td align="left">					655350528973				</td>				<td align="left">					Bonnet Blooms Pinkle				</td>				<td align="left">					Prima Marketing				</td>			</tr>					<tr>				<td align="left">					718813429870				</td>				<td align="left">					Thickers Bewitched- Melon				</td>				<td align="left">					American Crafts Lc				</td>			</tr>					<tr>				<td align="left">					895707019451				</td>				<td align="left">					The Halloween Collection Letter Stickers				</td>				<td align="left">					Reminisce				</td>			</tr>					<tr>				<td align="left">					009710116087				</td>				<td align="left">					A Spring Tail				</td>				<td align="left">					House Mouse				</td>			</tr>					<tr>				<td align="left">					725718986803				</td>				<td align="left">					Fall Leaf				</td>				<td align="left">					Inkadinkado				</td>			</tr>					<tr>				<td align="left">					876042006818				</td>				<td align="left">					Stripe				</td>				<td align="left">					Three Bugs In A Rug				</td>			</tr>					<tr>				<td align="left">					759668102051				</td>				<td align="left">					Embrace Stickeroos				</td>				<td align="left">					Penny Black				</td>			</tr>					<tr>				<td align="left">					655350840631				</td>				<td align="left">					Alpha Sticker- Cream				</td>				<td align="left">					Prima Marketing				</td>			</tr>					<tr>				<td align="left">					643077625655				</td>				<td align="left">					A To Z- Alphabet Page Pad				</td>				<td align="left">					K & Company, Llc				</td>			</tr>				</table><hr /><form method="post" name="Haskins" action="http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=feature_update"><span id="test">sku: </span><input type="text" size="10" maxlength="40" name="sku"><br /><input type="submit" value="Submit" name="send"><input type="submit" value="Clear list" name="clear"></form><script type="text/javscript" language="Javascript"> window.onload=function(){alert ("This boy is working");document.Haskins.sku.focus();}</script> </td></tr></table> <p><hr size=1 color=#366090><div align=right class=normal><i>Admin Area</i></div></body></html>

  4. #4
    Join Date
    Oct 2009
    Posts
    20

    That Code tag is not the best

    I must not be using it right, or notepad ++ doesn't copy right. Here's the code in more readable form:

    <h3>Featured product updater for Vivian's feature spotlighting delight.</h3>

    <table width="538">
    <tr>
    <td width="25&#37;" align="center">
    SKU
    </td>
    <td width="50%" align="center">
    Description
    </td>
    <td width="vendor" width="25" align="center">
    Vendor
    </td>
    </tr>
    <? if ($features != 0) : ?> <!--I'm sure we can just use the variable as an array or a number without recasting-->
    <? foreach ($features as $feature) : ?>
    <tr>
    <td align="left">
    <?=$feature['sku'] ?>
    </td>
    <td align="left">
    <?=$feature['name'] ?>
    </td>
    <td align="left">
    <?=$feature['vendor'] ?>
    </td>
    </tr>
    <?endforeach?>
    <? else :?>
    <tr>
    <td colspan="3">
    The table is empty
    </td>
    </tr>
    <? endif ?>
    </table>
    <hr />
    <form method="post" name="Haskins" action="<?=$full_url?>">
    <span id="test">sku: </span><input type="text" size="10" maxlength="40" name="sku"><br />
    <input type="submit" value="Submit" name="send">
    <input type="submit" value="Clear list" name="clear">
    </form>
    <script type="text/javscript">
    window.onload=init;
    function init(){
    alert ("This boy is working");
    document.Haskins.sku.focus();
    }
    </script>
    Last edited by oaishm; 10-04-2009 at 04:06 PM. Reason: code tag doesn't copy well

  5. #5
    Join Date
    Oct 2009
    Posts
    20

    four days and 108 views later...

    Well, after beating my head against the wall for five days and reading books everywhere, I've figured out how to make an html page locally to test code in stead of uploading all the time. I've tried firebug, which is quite handy. I've even reduced it to the smallest item possible, but still can't seem to get it to work.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
    <!-- saved from url=(0074)http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=feature_update -->
    <HTML><HEAD><TITLE>Administration - Catalog</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
    </HEAD>
    <BODY >
          <FORM name=Haskins 
          action=http://www.scrapbookingsuppliesrus.com/?admin=catalog&amp;layer=feature_update 
          method=post><SPAN id=test>sku: </SPAN><INPUT maxLength=40 size=10 
          name=sku><BR><INPUT type=submit value=Submit name=send> <INPUT type=submit value="Clear list" name=clear> </FORM>
          
        
    <SCRIPT type=text/javscript>
    window.onload=function(){
    alert ("This boy is working");
    document.Haskins.sku.focus();
    }
    </SCRIPT>
    </BODY></HTML>
    But then, just as I was about to hit the submit reply button, I figured it out. As you can see from my earlier posts, I misspelled javascript in the tag. I can't believe it...

  6. #6
    Join Date
    Sep 2009
    Location
    USA
    Posts
    34
    lol happens to all of us sooner or later :-)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles