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

Discussion in 'Web Design & Coding' started by Glaanieboy, Apr 28, 2004.

  1. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    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?
     
  2. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    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. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    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?
     
  4. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
  5. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
  6. albybum

    albybum Penguin Rancher

    Messages:
    280
    Location:
    Elizabethton, TN
    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.
     
  7. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Its just like that :p