Page 1 of 1

what's wrong with the piece of html code?

Posted: Wed Apr 13, 2005 11:47 pm
by php12342005

Code: Select all

<html>
<head>
<script type=&quote;text/javascript&quote;>
var mySel;
function getMultiple(ob)
{
if (ob.selectedIndex != -1)
{
mySel=ob.options&#1111;ob.selectedIndex].value;
}
}
function DispPage()
{
confirm(mySel);
location.href=mySel.toString()
}
</script>
</head>
<body>

<form name='frmSelect'>
<select name='numbers' multiple='multiple' onblur='getMultiple(document.frmSelect.numbers);'>
<option value=&quote;http://www.sun.com/index.html&quote;>Index</option>
<option value=&quote;http://www.sun.com/download/index.jsp&quote;>Downloads</option>
</select>
<input type='submit' value='Go' onclick=DispPage();>
</form>
</body>
</html>
======================================
I hope users can go to selected sun's web-page (as new window) when they press button go .

could u help me to find errors?

thanks

Jcart | Please use

Code: Select all

tags[/color]

Posted: Thu Apr 14, 2005 1:23 am
by Smackie
First off why are you posting a html/javascript in a php help form?? and second of all is there any error that pop up??

Posted: Thu Apr 14, 2005 2:04 am
by n00b Saibot
Working code (edited to help you & suit me ;))

Code: Select all

<html> 
<head> 
<script type=&quote;text/javascript&quote;> 
var mySel; 
function getMultiple(ob) 
{ 
if (ob.selectedIndex != -1) 
  mySel=ob.options&#1111;ob.selectedIndex].value; 
} 
function DispPage() 
{ 
confirm(mySel);
location.href=mySel.toString();
} 
</script> 
</head> 
<body> 
<form name='frmSelect' action=&quote;javascript:DispPage()&quote;> 
<select name='numbers' multiple='multiple' onblur='getMultiple(this)'> 
<option value=&quote;http://www.sun.com/index.html&quote;>Index</option> 
<option value=&quote;http://www.sun.com/download/index.jsp&quote;>Downloads</option> 
</select> 
<input type='submit' value='Go'> 
</form> 
</body> 
</html>

Posted: Thu Apr 14, 2005 3:46 am
by php12342005
Hi Saibot,
it works well.
(but) do u know how to pop up selected link to a new window? similar to HTML TAG target="_new"?

thanks.

Posted: Thu Apr 14, 2005 4:02 am
by n00b Saibot
php12342005 wrote:(but) do you know how to pop up selected link to a new window? similar to HTML TAG target="_new"?
Why don't you use target='_new'. Do you want the confirmation in anew window or the page to open in a new window :?:
Could you explain this a bit further please. :?

Posted: Thu Apr 14, 2005 4:19 am
by php12342005
yes.
when i click button "Go", the selected page (Sun's link) replaces current page in same window - i hope selected page is in a new window (current page is still there).

how to use 'target="_new" in javascript? i tried but it didn't work.

Posted: Thu Apr 14, 2005 4:26 am
by n00b Saibot
OK for that you have to use the window.open method.

Code: Select all

function DispPage()
{
 confirm(mySel); //I dont know why it is here...
 window.open(mySel.toString());
}

Posted: Thu Apr 14, 2005 4:29 am
by JayBird
Moved to client side