[javascript] What is wrong with this? (see thread)

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
Code:
<html>
 <head>
  <title>Javascript Test</title>
  <script language="text/javascript">
  function jumpTo(confirm_text,alert_text,url){
    if(confirm_text){
      if(confirm(confirm_text)){
        location.href = url;
      }else{
        if(alert_text){
          alert(alert_text);
        }
      }
    }
  }
  </script>
 </head>
 <body>
  <a href="javascript:void(0);" onClick="javascript:jumpTo('Confirm this','ALERT!','http://www.whatismyip.com');">Click me</a>
 </body>
</html>

This piece of HTML/javascript should display a text in a confirm dialog and when canceled it should display the alert box. But when I click the 'Click me' link, it does nothing. What is wrong with this piece of code?
 
OK, Glaanie you had me stumped so I knew it was something simple

<script language="text/javascript">

to

<script type="text/javascript">

Took me 20 minutes to figure that one out :D
 
Ah I see how I made the mistake. I use tsWebeditor for my webediting tasks and when I typed '<script ' a pulldown menu appeared with two options, 'language' and 'src'. I am still wondering why it didn't include 'type'. btw what does 'language' do then?
 
Language was how browsers determined the type of the script in the past, but it is deprecated now. Type is the more current way to specify a script language type.

It is good practice to have both as anyone with an old or limited browser may only look for a type attribute. With the language attributeyou can set specific versions of languages for your browser to use. Say you have a script that only works with JavaScript 1.1, you would put language="JavaScript1.1"

<script type="text/javascript" language="javascript">

[edit] jeez you people are quick on the draw. Was seconds late.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back