• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

#1
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?
 

j79zlr

Glaanies script monkey
Political User
#2
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
 
#3
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?
 

albybum

Penguin Rancher
#6
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 posts

Latest profile posts

Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,015
Latest member
evaiwhitis