www.webdeveloper.com
Results 1 to 6 of 6

Thread: Can someone tell me why this script doesn't work?

  1. #1
    Join Date
    Jan 2010
    Location
    Fort Myers, Florida, USA
    Posts
    14

    Unhappy Can someone tell me why this script doesn't work?

    I'm pulling my hair out on this one. When I get it working there will be more model numbers and more manuals added.
    Right now, when I run it it pops up the alert telling me my manual doesn't exist before I even enter anything.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <head>
      <title></title>
      <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    </head>
    <body>
    <FORM NAME="askModel">
    Please enter your model number : <INPUT TYPE="text" NAME="model" SIZE="40">
    </INPUT>
    <INPUT TYPE="button" VALUE="Submit">
    </INPUT>
    </FORM>
    <script language=""javascript" type="text/javascript">
    <!--
    manual = document.askModel.model.value;
          switch(manual) {
    	  case 'gcva070bx40':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva070cx40':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva090bx50':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva090cx50':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  default:
    	  alert('Your manual does not exist')
    	  }
    	  -->
    	  </script>
    </body>
    </html>
    Thanks to anyone with some insight.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <script type="text/javascript">
    function pdfDoc() {
    manual = document.askModel.model.value;
          switch(manual) {
    	  case 'gcva070bx40':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva070cx40':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva090bx50':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  case 'gcva090cx50':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  default:
    	  alert('Your manual does not exist')
    	  }
    }
    </script>
    
    <style type="text/css">
    * {margin:0;padding:0;}
    </style>
    
    </head>
    <body>
    <form name="askModel" action="#" onsubmit="pdfDoc(); return false;">
    <div>
    <label>Please enter your model number : <input type="text" name="model" size="40"></label>
    <button type="submit">Submit</button>
    </div>
    </form>
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Jan 2010
    Location
    Fort Myers, Florida, USA
    Posts
    14
    OMG, that works perfectly!
    Thank You, Thank You, Thank You!

  4. #4
    Join Date
    Jan 2010
    Location
    Fort Myers, Florida, USA
    Posts
    14
    One question if you don't mind. Is it ok/proper to put like 200 cases in a switch statement? Or is there a better way?

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    What you have now can be altered to:
    Code:
    function pdfDoc() {
    manual = document.askModel.model.value;
          switch(manual) {
    	  case 'gcva070bx40':
    	  case 'gcva070cx40':
    	  case 'gcva090bx50':
    	  case 'gcva090cx50':
    	  window.open('RP6612001.pdf', '_blank');
    	  break;
    	  default:
    	  alert('Your manual does not exist')
    	  }
    }
    Other solutions may be possible depending the relationship between model and pdf.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  6. #6
    Join Date
    Jan 2010
    Location
    Fort Myers, Florida, USA
    Posts
    14
    That will be a lot less typing. Thanks again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles