Now I need help with javascript...

  • Thread starter Thread starter Jpec07
  • 5 comments
  • 407 views
Messages
5,842
Messages
Forgotten Wing
Alright, I have this menu that I want to have the buttons link to stuff. I've figured out how to do this; but now I want to make one that refers to an iFrame that I have on the page. Can someone tell me how this would work (like, what I'd need to have as syntax to a certain command or something). I'd really appreciate this; thanks in advance.
 
You want a link to open in an iFrame somewhere on the page? There is no need for Javascript, it can be achieved with simple HTML markup. You have to give your iFrame a name so you can use the target attribute on your links.

Say this is your existing iFrame tag:
Code:
<iframe src="lookma.htm">You're browser does not support iFrames. Please upgrade and try again.</iframe>

All you have to do is add name="" to it, like so:
Code:
<iframe src="lookma.htm" [color=red]name="foo"[/color]>You're browser does not support iFrames. Please upgrade and try again.</iframe>

I think it's name anyway. If that doesn't work, try id="foo". Oi, I haven't done this for ages and I don't have Dreamweaver installed at the moment. :grumpy:

Anyway, now you just have to add target="foo" to your link, like so:
Code:
<a href="lookma2.htm" [color=red]target="foo"[/color]>Pimpin'</a>

Oh, and you should never resort to having your website rely on Javascript. In that last thread you made ("CSS Links") I said that 11% of the web don't have Javascript enabled, with makes your page instantly inaccessible.
 
I mean have to the link come in from a dropdown menu type of thing in a form, not have just an a href=blah.html with target=framename. I'm talking have a thing where you select an option in the menu, hit a button, and the iframe changes. I know that that requires javascript...
 
This is the code I'm having trouble with:
Code:
<form name="menu1">
<select id="selectedPage1" name="selectedPage1" onChange="document.iframe1.src=document.menu1.selectedPage1.value; return true">
<option value = "" selected>Choose a Site!</option>
<option value = "site1.html">Site 1</option>
<option value = "site2.html">Site 2</option>
<option value = "site3.html">Site 3</option>
<option value = "site4.html">Site 4</option>
</select>

</form>
<IFRAME name="iframe1" id="iframe1" src="index.html" width=400 height=350 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME>

now, I have it set right now so that no error messages pop up; however, it now does nothing. if I change the "src=document.menu1.selectedPage1.value" to any kind of method, an error message pops up. Now, is there a special method or function I have to put in in order to make it do something? Thanks in advance.
 
I've never used forms before. Forms should only be used for that - forms. Like, subscriptions and such. But anyway, it looks to be basically the same thing I said earlier. Just put links in your forms options and use the target attribute.

As its only a basic form, I don't think you'd need values and such. But like I said earlier, I haven't used them much before.

Code:
<form name="menu1">
  <select id="selectedPage1">
    <option>[color=red]<a href="lookma2" target="foo">Site 1</a>[/color]</option>
  </select>
</form>

And then your iframe:
Code:
<iframe name="foo" src="index.html"></iframe>

Just looking at the code you provided, it's very messy and non-standards compliant. All your coding should be done in lowercase and all your values should be enclosed in ""s. So in your iframe tag where you have width=400, it should essentially be width="400".
 
Originally posted by Shannon
I've never used forms before. Forms should only be used for that - forms. Like, subscriptions and such. But anyway, it looks to be basically the same thing I said earlier. Just put links in your forms options and use the target attribute.

As its only a basic form, I don't think you'd need values and such. But like I said earlier, I haven't used them much before.

Code:
<form name="menu1">
  <select id="selectedPage1">
    <option>[color=red]<a href="lookma2" target="foo">Site 1</a>[/color]</option>
  </select>
</form>

And then your iframe:
Code:
<iframe name="foo" src="index.html"></iframe>

Just looking at the code you provided, it's very messy and non-standards compliant. All your coding should be done in lowercase and all your values should be enclosed in ""s. So in your iframe tag where you have width=400, it should essentially be width="400".

I had considdered putting links in the menu, and it seems feasable except that I would have to edit the css so that the links don't do anything, but I suppose that wouldn't be so hard. I think I'll take your advice and go for the links in the menu instead of having just a normal menu, so thanks.

Also, I know that the coding should all be in lowercase letters, but I didn't make that coding (borrow'd from lissaexplains.com as it's a pretty good template). Again, I'm blaming the quotas on lissaexplains as I didn't really write that bit of coding (just adjusted a couple of the values). I know iframes and that stuff, I was just trying to make my menu more betterer...
 
Back