Log in

View Full Version : Exclude action on Index 0 and 1 in a Combo Box onChange event



vturner
11-04-2019, 03:54 PM
Hi experts,

On my website, www.vannturner.com, I have 8 combo boxes which list the URLs of retailers (the actual product page) where my novels can be bought.

Index 0 is always the name of the name of the box, eg “Retailers”. Most have Index 1 as Your local bookstore. Both of those have an empty string as arg.

On the onChange event, I am passing as arg the URL to the gothere function. It works just fine for Indexes 2 and greater, but if someone selects Index 1, it opens a copy of my URL in a new window.

How to tell the script that if Index 0 or 1 is selected to do nothing?

WORKS, but does not exclude Index 0 or 1:


<script type="text/javascript">
function gothere(arg){
var arg
newwindow=window.open("")
newwindow.location=arg;
}
</script>

My attempt to exclude the first two items in the box. DOES NOT WORK:

<script type="text/javascript">
function gothere_new(arg){
var arg
if(arg != null && arg.length() < 2) { return;}
else {
newwindow=window.open("")
newwindow.location=arg;
}
}
</script>

I admit I have not studied Java, but have a background in VB and dot.Net. I'm sure my syntax is just wrong.

What is the correction?

Thanks for your help!
Vann

coothead
11-05-2019, 10:19 AM
Hi there vturner,


and a warm welcome to these forums. ;)

Try it like this...




function gothere( arg ){
if ( arg !== '' ) {
window.open( arg );
}
}



coothead

vturner
11-05-2019, 03:17 PM
coothead, MANY THANKS!

Works perfectly. And I'm indebted.
If I can ever do anything for you, merely ask.

Vann

coothead
11-05-2019, 03:31 PM
If I can ever do anything for you, merely ask.


To be on the the safe side, I would
suggest that you remove this...



function gothere_new(arg){
var arg
if(arg != null && arg.length() < 2) { return;}
else {
newwindow=window.open("")
newwindow.location=arg;
}
}

function gothereORIG(arg){
var arg
newwindow=window.open("")
newwindow.location=arg;
}


Then you may smile benignly. :)



coothead

vturner
11-05-2019, 05:29 PM
coothead,

Good idea. I'll remove it since it has no use.

Your willingness to help a stranger speaks well of you.

You are probably a man greatly loved, with many friends. Easy to see why.

Best wishes,
Vann

coothead
11-05-2019, 05:52 PM
You are probably a man greatly loved, with many friends.


It is funny that you should say that as I'm actually a
recluse and don't have any friends as such.

What I do though, is try to treat everyone that I meet
with respect and of course, as a result, I always...


smile benignly :)



coothead

vturner
11-06-2019, 08:02 PM
Hi coothead,

Somehow I missed this yesterday in my in-box.

We've got something in common. I too am somewhat a recluse here in the mountains with my dogs, woodstove, mountains, forest and sky. I'm fortunate that I have excellent neighbors (though you see their their houses from mine). We do for each other, whatever is needed. I'll be walking over in a bit a tend one of my neighbors' dogs, as a funeral in the family has called them away. And I, too, try to treat everyone respectfully. (Love your "smile benignly" closing.

Vann