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

msgBox and hyperlinks

Status
Not open for further replies.

FlatHead

Programmer
Oct 13, 2000
50
GB
I have a drop Down box with some values such as Robot 1,Robot 2, Robot 3....

All i want is once the user select each one from the Drop down menu to automatically linmk them to external URLs

for example for robot 1 i want : e.t.c e.t.c

Pleasee help
Regards ZAC
 
i want to add that the msgbox which is the subject on my first message is drop down box.
 
this should work for you:

<script>

function findIt()
{
var criteria,engine,search,frm;
frm = document.benlucbenluc
criteria = frm.benlucben.value;
engine = frm.benluc.options[frm.benluc.selectedIndex].value;
switch(engine)
{
case '1':
search=&quot; break;
case '2':
search=&quot; break;
case '3':
search=&quot; }
window.location=search
}
</script>

<form action=&quot;javascript:findIt()&quot; name=&quot;benlucbenluc&quot;>
Search for:&amp;nbsp;<input name=&quot;benlucben&quot;>&amp;nbsp;with
<select name=&quot;benluc&quot;>
<option value=&quot;1&quot;>Altavista
<option value=&quot;2&quot;>Yahoo
<option value=&quot;3&quot;>Web Crawler
</select>
<script>
if(document.all){document.write('<input type=&quot;submit&quot; value=&quot;Search&quot;>')}
else{document.write('<input type=&quot;button&quot; onClick=&quot;findIt()&quot; value=&quot;Search&quot;>')}
</script> jared@aauser.com
 
btw, that should work for IE4+,NS4+,and opera 5+ jared@aauser.com
 
I thankfully used your script and i want to thank you for your help.
It worked successfully after some modifications i did cause i had to use it on an asp page.
But the main source is the same.
Respect.
ZAc
 
Can you tell me how to get a MsgBox to appear after a button's onclick event on an ASP page? Thanks.
 
Dave,
Code:
<input type=&quot;button&quot; value=&quot;Show Msg&quot; onClick=&quot;window.alert('This is a JavaScript Message');&quot;>
Or if the button is already performing a method, just separate the two with a semi colon like this.
Code:
<input type=&quot;button&quot; value=&quot;Show Msg&quot; onClick=&quot;window.alert('This is a JavaScript Message');window.alert('This is a different method');&quot;>
Or if the button is calling a function, you can just write the window.alert() method in that function.

Boy, I sure hope that's what you meant by a Message Box.

ToddWW
 
FlatHead,

Here's a JavaScript function that will read the address from the option value (if you can spare it). This way, the function is re-usable for any select list. I have this function stored in an external .js file and call it from hundreds of select lists in my application. Looks like this.
Code:
function goApp(srcElement) {
  if (srcElement.options[srcElement.selectedIndex].value != &quot;&quot;) {
    var address = srcElement.options[srcElement.selectedIndex].value
    srcElement.options[0].selected = true
    window.location.href = address
  } else {
    srcElement.options[0].selected = true
  }
}
Here's what a select list looks like.
Code:
<select name=&quot;webList&quot; onChange=&quot;goApp(this);&quot;>
  <option value=&quot;&quot;>Select a Search Engine</option>
  <option value=&quot;[URL unfurl="true"]www.yahoo.com&quot;>Yahoo</option>[/URL]
  <option value=&quot;[URL unfurl="true"]www.msn.com&quot;>MSN</option>[/URL]
  <option value=&quot;[URL unfurl="true"]www.google.com&quot;>Google</option>[/URL]
</select>
Now in my example I always have the first option say something like Select Something with a value of nothing. The function is designed to ignore that, as well as it is designed to ignore anything else in the select list with a value of &quot;&quot;. This way, you can put seperators in your select list that will be ignored. What's important is that the function will return the list back to the first option after the function is run. So you could have a list that looked like this.
Code:
<select name=&quot;webList&quot; onChange=&quot;goApp(this);&quot;>
  <option value=&quot;&quot;>Select a Web Site</option>
  <option value=&quot;&quot;>-----------------</option>
  <option value=&quot;&quot;>Sports Sites</option>
  <option value=&quot;[URL unfurl="true"]www.espn.com&quot;>ESPN</option>[/URL]
  <option value=&quot;[URL unfurl="true"]www.abcsports.com&quot;>ABC[/URL] Sports</option>
  <option value=&quot;[URL unfurl="true"]www.mnf.com&quot;>Monday[/URL] Night Football</option>
  <option value=&quot;&quot;>-----------------</option>
  <option value=&quot;&quot;>Search Engines</option>
  <option value=&quot;[URL unfurl="true"]www.yahoo.com&quot;>Yahoo</option>[/URL]
  <option value=&quot;[URL unfurl="true"]www.msn.com&quot;>MSN</option>[/URL]
  <option value=&quot;[URL unfurl="true"]www.google.com&quot;>Google</option>[/URL]
  <option value=&quot;&quot;>-----------------</option>
</select>
The function works the same on any select list where you call the function in the onChange event handler and have the URL in the option value. Don't forget to include the parameter this in the function call. That way, no matter where the function is, or where the select list is put in your document, that passes the select list by reference to the function. Well I shouldn't really say that. The function needs to be on the current page or in a .js file referenced on the current page.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top