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

How to use target with javascript location.href

Status
Not open for further replies.

tommytx

Programmer
Nov 27, 2002
28
US
works just fine.
****************
<script>
function getsub() {
location.href="vbchsub.htm";
}

will not work
*************
<script>
function getsub() {
location.href="vbchsub.htm" target="myiframe";
}


works fine but must use a form. (but if I add another form on this page it stops working.)
Here I just change the action with an existing target and it works fine.. until i add the second form.
*****************************
<script>
function getsub() {
myform.action="vbchsub.htm";
myform.submit();
}


form name=myform action="chessub.htm" target="myiframe"></form>


What I want to be able to do is have the javascript go to what ever location I send it by telling it what the url is.
so you can better understand what I am doing, below is a more complete script.

<script>
function getsub() {
$sel = city.value;
$sel = city.value + "sub.htm";
document.myform.action=$sel;
document.myform.submit();
}
</script>

Bottom line is when I click on different cities in a select dropdown box, a list of all subdivisions in that city are loaded

into an iframe. Might me chessub.htm or vabesub.htm and etc... ches meaning city of chesapeake.

I had the whole thing working using the simple form above as it would allow a target, but as soon as I added the regular form

required for the program it stopped working... as if only one form can be on the page... even though each form had a

different name like name=myform and name=mainform.

Bottom line is there anyway to make javascript hit a target....

thanks
Tom

 
>location.href="vbchsub.htm" target="myiframe";
[tt]location.href="vbchsub.htm"[highlight];[/highlight] target="myiframe";[/tt]

The rest, it seems it is an almagame of all the ideas and lacking coherence.
 
Thanks Tsuji, that was exactly what I was looking for, but it did not work for me.. check it out at
I have 3 examples set up:
1. The example you gave which does not put the data in the iframe.. can you look at the source and see if I did anything wrong. Thanks.

2. Works ok but fails if I add another form of any kind on the page..

3. Works using the form and changing the action code via javascript, but it also fails if I add another form on the page... no matter what I name the form...

The one I really want to work is the one TSuji suggested.. does anyone have suggestions...

Bottom line... what it should do is replace the iframe text without opening its own window..

adam0101... thanks for your suggestion, I know that one works but as you can see I can't use a new window, it needs to replace the code in the iframe box...
 
oh... by the way... if you test the page above, simply click on each choice and see what it does then simply click the back button to get the old data back in the box for the next test... other wise you need to reload as refresh will not roload the old data..

Thanks again for any suggestions.
 
[0] My first response was only intended to point out the syntactic problem. It was not intended to resolve any functional problem.

[1] I have now taken a look at the demo page. This is how it is done with getsub_1().
[tt]
function getsub_1() {
[red]//[/red]location.href="norfsub.htm"; target="myiframe";
document.getElementsByName("myiframe")[0].contentWindow.location.href="norfsub.htm";
}
[/tt]
[2] In the anchor(s) why is there a colon after the href?
><a href="javascript:getsub_1()"[highlight]:[/highlight]>Version one</a><br>
[tt]<a href="javascript:getsub_1()">Version one</a><br>[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top