[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 😀
 
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.

Forum statistics

Threads
62,021
Messages
673,242
Members
5,640
Latest member
Kgkass
Back
Top