PDA

View Full Version : JavaScript problem??Someone hlp


Gideon
09-12-2004, 11:11 AM
:mad: :mad:
cud somwonw help me here.
This JavaScript code is'nt working.I am doing a tute on JavaScript and everytime a try an exercise it fails.So i jus give up the home work and move on....
anyway now i got really fed up and came here

ps. this code was made in dreamweaver mx and many times JavaScript fuctions from many sites i visit dont work, whereas many sites' codes work well.( i hav internet explorer 6.0.2600.0000)an' theres the original htm file attached

Thanx
gidoen

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Kool Browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--hide me
function fixUrl (the_url)
{
var the_url = the_url.toLowerCase():
var first_seven = the_url.substring(0,7);
if (first_seven != 'http://')
{
the_url = 'http://'+ the_url
}
return the_url
}
function addToFav ();
{
var url = prompt("Wats the url??", "http://");
if ((url == "") && (url == null)) {
alert("Thats not a url, LOSER");
} else {
var good_url = fixUrl(url);
var the_fav = window.document.fav_form.favorites;
var num_option = the_fav.options.length;
var new_option = new Option;
new_option.text = good_url;
the_fav.options[num_options]= new_option;
}
}
function goThere ()
{
var url = window.document.fav_form.favorites.options[url.selectedIndex].text;
var good_url = fixUrl(url);
new_window = window.open(url, "window_one");
}
// show me-->
</script>
</head>
<body>
<p align="center"><font color="#990000" size="5" face="Comic Sans MS">KoolBrowser
2000 </font></p>
<form name="fav_form">
<font size="4" face="Comic Sans MS">The Favorites Menu</font>
<select name="favorites" size="1" onChange="gothere();">
<option>Pull Down 2 Go 2 ur Fav. Site</option>
<option>http://www.actionscript.com</option>
<option>http://www.flashkit.com</option>
<option>http://www.webmonkey.weird.com</option>
<option>http://www.nicksplat.com</option>
</select>
<a href="#" onClick="goThere(); return false;">Add To Favorites </a>
</form>

<p align="center"><font size="2">(Click the Add2 Fav. Btn to add to ur fav menu)</font></p>
<hr>
<p><font face="Comic Sans MS">This a Typical JavaScript webpage.It was contructed
by me Gideon.</font></p>
</body>
</html>

programmer_neo
09-17-2004, 04:05 PM
I cleaned up your code and it works now.
Compare mine to yours.
You had some semicolons, where none should be.
You misnamed your functions.

Suggestion:A great way to debug you javascript code is actually to use
Netscape. It has a better javascript debugger than IE.
(One of it's only advantages.)

Just run your page, then type in the url line ... javacsript:
(remember the colon) It launches the debugger and tells you what line is bad
and a possible solution.




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Kool Browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--hide me
function fixUrl (the_url)
{
the_url = the_url.toLowerCase();
var first_seven = the_url.substring(0,7);
if (first_seven != "http://")
{
the_url = "http://"+ the_url
}
return the_url
}
function addToFav ()
{
var url = prompt("Wats the url??", "http://");
if ((url == "") && (url == null)) {
alert("Thats not a url, LOSER");
} else {
var good_url = fixUrl(url);
var the_fav = window.document.fav_form.favorites;
var num_option = the_fav.options.length;
var new_option = new Option;
new_option.text = good_url;
the_fav.options[num_options]= new_option;
}
}
function goThere (myUrl)
{

var good_url = fixUrl(myUrl);
new_window = window.open(good_url, "window_one");
}
// show me-->
</script>
</head>
<body>
<p align="center"><font color="#990000" size="5" face="Comic Sans MS">KoolBrowser
2000 </font></p>
<form name="fav_form">
<font size="4" face="Comic Sans MS">The Favorites Menu</font>
<select name="favorites" size="1" onChange="goThere(this.value);">
<option>Pull Down 2 Go 2 ur Fav. Site</option>
<option>http://www.actionscript.com</option>
<option>http://www.flashkit.com</option>
<option>http://www.webmonkey.weird.com</option>
<option>http://www.nicksplat.com</option>
</select>
<a href="#" onClick="goThere(); return false;">Add To Favorites </a>
</form>

<p align="center"><font size="2">(Click the Add2 Fav. Btn to add to ur fav menu)</font></p>
<hr>
<p><font face="Comic Sans MS">This a Typical JavaScript webpage.It was contructed
by me Gideon.</font></p>
</body>
</html>