Results 1 to 7 of 7

Thread: Crappy Javascript

  1. #1

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Angry Crappy Javascript

    Here is the page that I am making below:

    Code:
    <html>
    	<head>
    		<title>~~~~***Melissa***~~~~</title>
    		<script language="javascript">
    			function show_page(page_number)
    			{
    				//Change the source of the inline frame
    				if (page_number == 1)
    					Main.src="MelissaHome.html";
    				if (page_number == 2)
    					Main.src="MelissaPoems.html";
    				if (page_number == 3)
    					Main.src="MelissaMusic.html";
    				if (page_number == 4)
    					Main.src="MelissaArt.html";
    			}
    		</script>
    	</head>
    
    	<body style="background-image:url(MelissaInterface.jpg); background-repeat:no-repeat; background-position:center; background-color:white;">
    
    		<!-- The navigation table -->
    		<table border="0" cellpadding="5" cellspacing="0" cols="1" style="width:188px; height:310px; position:absolute; top:290px; left:153px;">
    			<tr>
    				<td align="center"><input id="cmdHome" type="button" value="Home" onclick="show_page(1)" /></td>
    			</tr>
    			<tr>
    				<td align="center"><input id="cmdPoems" type="button" value="Poems" /></td>
    			</tr>
    			<tr>
    				<td align="center"><input id="cmdMusic" type="button" value="My Music" /></td>
    			</tr>
    			<tr>
    				<td align="center"><input id="cmdArt" type="button" value="My Art" /></td>
    			</tr>
    		</table>
    
    		<!-- The inline frame for the actual pages with content -->
    		<iframe name="Main" frameborder="0" src="" style="width:460px; height:335px; position:absolute; top:200px; left:400px;"></iframe>
    
    	</body>
    </html>
    In the ONCLICK event on the first button, did I script that right because it's not working at all. The source of the inline frame doesn't change. It just stays blank. Or did I script the function wrong? HELP!!!!!!!!
    Only those who try will become.

    Find me on identi.ca

    Twitter @gfmartin05

    Linux Wrap

  2. #2
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Crappy Javascript

    Location
    .replace(URL) - Requires a URL as a parameter. It loads the document at the URL on top of the current document. A new entry entry is not placed in the history object.

    So I believe the javascript to get to the iframe is something like...

    document.getElementById('hiddenframe').location.replace("newpage");

    My suggestion is to download FireFox, and check out the JavaScript console, it gives pretty good error messages compared to IE.
    Don't Rate my posts.

  3. #3

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: Crappy Javascript

    I downloaded FireFox and looked at the JavaScript Console (which was a very helpful idea so thank you for that) but it says that my iframe has no properties. It's almost like it don't even exist. I get the following error:

    document.getElementById(Main).location has no properties

    I change the code only for the first button and it looks like this:

    Code:
    document.getElementById('Main').location.replace("MelissaHome.html");
    What the heck is going on here?

    EDIT:

    I removed the code and went back to the original code I had before and I clicked the button and checked the JavaScript console. It didn't have any errors but no sites were appearing in the iframe.
    Only those who try will become.

    Find me on identi.ca

    Twitter @gfmartin05

    Linux Wrap

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Crappy Javascript

    Make sure your iframe has a id="Main".

    You might be able to just do,
    document.Main.location.replace(..) without giving it an id, but I'm not sure to be honest, the structure of documents was always really confusing.
    Don't Rate my posts.

  5. #5

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: Crappy Javascript

    Thanks for you help through this entire thing by the way.

    Yeah I did that but then I found something else funny. When I set a source page for the iframe in src attribute of the iframe tag, the source page won't even show up! The source file direction is correct but nothing is working.
    Only those who try will become.

    Find me on identi.ca

    Twitter @gfmartin05

    Linux Wrap

  6. #6

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: Crappy Javascript

    Don't worry about it anymore. I quit. I tried retyping the code, giving it an ID, using the getElementById() method, everything. Nothing is working. It's almost like the parser isn't even picking it up as an object.
    Only those who try will become.

    Find me on identi.ca

    Twitter @gfmartin05

    Linux Wrap

  7. #7
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Crappy Javascript

    Just doing alittle reading, you may be able to use the src property, but try giving it the full path to the file (www.server.blah/blah/Melissa.html).
    Don't Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width