Click to See Complete Forum and Search --> : Hybrid Jumplink: Popup & Parent target


freaksarise
05-09-2003, 12:43 PM
I am working on a very basic function but have not seen it anywhere.

Usually jumplink pulldowns either target a blank window or the parent. I want to make an option that can do both in one pulldown.

So far I made a function that determines which option was chosen and based upon the result either popsup or straight links.

To the end user or client the solution has been solved. In other words - this works. However as a newbie javascript programmer. I would like to make an easier manageable alternative.

I will place a value with each option that not only tells the .location but also a variable popUp = YES or NO.

This way it can easily be modified in one place.

Any ideas? I think I will place 2 values in each option like this link.htm|popUp="yes"

I just need to figure out how to retrieve and split this value.
Thanks for any brainstorming or thoughts!
FA

pyro
05-09-2003, 12:52 PM
If you have it in a variable, just do newvar = variablename.split("|"); this will retrurn an array (newvar[0] and newvar[1]) with your values.

Jona
05-09-2003, 12:57 PM
Something like....

<html><head>
<script>
function go(loc){
var a = loc.indexOf("&")+5;
var b = loc.length;
var pop = loc.substring(a, b);
a=0; b = loc.indexOf("&");
loc = loc.substring(a, b);
alert(loc)
if(pop=="true"){window.open(loc);}else{location.href=loc;}
}
</script>
</head><body>
<form name="myForm">
<select name="mySel" onChange="go(this.options[this.selectedIndex].value)">
<option value="-1" selected>Choose one:</option>
<option value="page_a.html&pop=true">Page_A</option>
<option value="page_b.html&pop=false">Page_B</option>
</select>
</form></body></html>

Jona
05-09-2003, 01:03 PM
Or, using Pyro's example:

<html><head>
<script>
function go(loc){
pop=loc.split("|");
if(pop=="pop=true"){window.open(loc);}else{location.href=laoc;}
}
</script>
</head><body>
<form name="myForm">
<select name="mySel" onChange="go(this.options[this.selectedIndex].value)">
<option value="-1" selected>Choose one:</option>
<option value="page_a.html|pop=true">Page_A</option>
<option value="page_b.html|pop=false">Page_B</option>
</select>
</form></body></html>

freaksarise
05-09-2003, 01:12 PM
Wow guys you were so fast I almost missed your replies.
These are great!!! Thank you so much.

"I'm giddy like Rosco P Cotrain over here"

Jona: Was your one line of code supposed to be "loc" instead of "laoc" Just wanted to see if it was a typo :)

Thanks again. I will try this asap.
FA

Jona
05-09-2003, 01:14 PM
Yup, it was a typo. It's supposed to be loc. (I hate that! :p)

freaksarise
05-09-2003, 01:26 PM
I just gave it a try but the browser is interpreting the URL as the correct address plus the un-split code:

http://www.freaksarise.com|pop=false

I guess the split function isn't working yet.

I will use both of your code to learn the best that I can. Here is the one I am starting with:

<script>
function go(loc){
pop=loc.split("|");
if(pop=="pop=true"){window.open(loc);}else{location.href=loc;}
}
</script>


AND


<form name="Pulldown_Form">
<select name="mySel" onChange="go(this.options[this.selectedIndex].value)">
<option value="-1" selected>Choose one:</option>
<option value="http://www.levlane.com|pop=true">LL</option>
<option value="http://www.freaksarise.com|pop=false">FA</option>
</select>
</form>


Thanks for your thoughts.
FA

Jona
05-09-2003, 01:30 PM
Oh, yeah, I forgot. Using Pyro's method, the URL isn't split. This should do the trick:

<script>
function go(loc){
pop=loc.split("|");
a=loc.indexOf("|");
loc=loc.substring(0, a);
if(pop=="pop=true"){window.open(loc);}else{location.href=loc;}
}
</script>
<form name="Pulldown_Form">
<select name="mySel" onChange="go(this.options[this.selectedIndex].value)">
<option value="-1" selected>Choose one:</option>
<option value="http://www.levlane.com|pop=true">LL</option>
<option value="http://www.freaksarise.com|pop=false">FA</option>
</select>
</form>

freaksarise
05-09-2003, 01:32 PM
ps...I am reading the Web Warrior Series Comprehensive Book Called JAVASCRIPT by DON GOSSELIN. They use it in colleges and stuff. Anyway, they are saying that the go() method is relative to your HISTORY or places you've already visited.

Is this not true since you fellas are using it in the way we are above?

Thanks
FA

Jona
05-09-2003, 01:37 PM
No, it is true, but we are creating a function named "go()." A method is not a function. history.go(-1), for example, is a method, and not a function. We are using go() as a function, not a method. You can change the name of the function, if you like, so that it won't confuse you.

Another thing, please make sure that your HTML is valid: http://validator.w3.org/ -- The W3C has a validator for your HTML. The page I posted is invalid HTML, and shouldn't be used. Every document needs a DTD, a TITLE, and META tags that specify the charset, script type, style type, and content type. This is just FYI. ;)

pyro
05-09-2003, 01:41 PM
Jona -

This might be a bit easier...

loc = loc.split("|");
alert(loc[0].substr(1));
alert (loc[1]);

That will alert both values. Less code. ;)

Jona
05-09-2003, 01:43 PM
Well... Okay, so it is less code... But.... At least mine works! :)

pyro
05-09-2003, 01:44 PM
Yep, both will work. Just thought you might not be aware of that method.

Cheers!

Jona
05-09-2003, 01:45 PM
Yeah..... ;)

freaksarise
05-09-2003, 01:49 PM
Jona
The URL works now. However the popup is not popping. It remains in the same window. I will keep playing too I don't want to keep asking you:).

Hey I will check out the validator thing immediately. That sounds scary. I think what you are saying though is that the page needs all the standard info like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">


I will go to that page now to see what you are referring to.
Thanks again.
FA

Jona
05-09-2003, 01:54 PM
All right, fine. We'll use Pyro's method... (:rolleyes: )

<script>
function go(loc){
pop=loc.split("|");
pop=pop[1]
loc=loc.split("|");
loc=loc[0].substr(1);
alert(pop)
if(pop=="pop=true"){window.open(loc);}else{location.href=loc;}
}
</script>
<form name="Pulldown_Form">
<select name="mySel" onChange="go(this.options[this.selectedIndex].value)">
<option value="-1" selected>Choose one:</option>
<option value="http://www.levlane.com|pop=true">LL</option>
<option value="http://www.freaksarise.com|pop=false">FA</option>
</select>
</form>

freaksarise
05-09-2003, 02:17 PM
LOL!!!
That works...no thanks to Jona...AHHHHH Just kidding oh great one.

I really appreciate your help, both of you. I learned several new things from this post today. I will now go dissect why this works with the newest lines you added, then try out Jona's original option to understand that as well.

I think that's a wrap.
Have a great day!
If you're like me you'll be up till at least 4am working and learning.

FA AKA Rich

Jona
05-09-2003, 02:35 PM
Good luck! ;)

freaksarise
05-09-2003, 02:51 PM
UPDATE:

I modifed the code a bit.
I didn't understand the need for the substring line and changed it to loc=loc[0].
It works.

<script>
function go(loc){
pop=loc.split("|");
pop=pop[1];

loc=loc.split("|");
// loc=loc[0].substr(0);
loc=loc[0];
alert(loc)
if(pop=="pop=true"){window.open(loc);}else{location.href=loc;}
}
</script>



I also thought since we already have the two values needed from the first split IE "link.htm" and "pop=value" why shouldn't we just use it right away like this:

pop=pop[1];
loc=pop[0];

unfortunately loc comes back undefined. Perhaps instead of loc I use another variable like: loc2=pop[0].

Just wanted to update anyone including people browsing archives someday.

Rich

Jona
05-09-2003, 03:04 PM
Well, that might work, but you have your variable taken after the array which is split, therefore making it not longer an array. Here:

loc=pop[0];
pop=pop[1];

Try that. Since pop isn't a two-dimensional array, pop[0] isn't an array. Putting your code together would result in: loc=pop[0][1] which does not exist and returns undefined. See? ;)

freaksarise
05-09-2003, 03:10 PM
Yes, Yes this is exactly what I figured out too.
Here is the final working code.


<script>
function go(loc){
pop=loc.split("|");
loc=pop[0];
pop=pop[1];
//alert(loc)
if(pop=="pop=true"){window.open(loc);}else{location.href=loc;}
}
</script>

Now we are done.
Very cool. I learned a lot today. I may come back and wrap it up with some comments for other newbies to learn.
R

pyro
05-09-2003, 03:15 PM
That works? Shouldn't it be loc = pop[0].substr(1); instead of loc = pop[0];

Jona
05-09-2003, 04:41 PM
Actually, Pyro, it does work. :)