what's wrong with the piece of html code?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

what's wrong with the piece of html code?

Post 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]
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post 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??
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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>
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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. :?
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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());
}
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Moved to client side
Post Reply