Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    hi guys, below is the script, currently this script allows person to input their age and if they input 0 -> 17 goes to one URL and all other go to another URL, well I need to add 40+ to go to a different URL then those other 2, so 20->39 will go to one URL and then 40+ will go to antoher URL, check the script.. can someone help me real quick with this?

    thanksssss


    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0051)http://www.umiacs.umd.edu/~gina/lbsc690/select.html -->
    <!-- saved from url=(0041)http://glue.umd.edu/~oard/690/select.html -->
    <HTML><HEAD><TITLE>Anytown Public Library Search Tool Selector</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>
    
    <SCRIPT language=JavaScript>
    <!--
    
    // This JavaScript Program sends users to a search engine or directory that
    // is appropriate to their age.
    // Original: 10/6/99 D. W. Oard
    // modified: 9/26/2003, Daqing He
    // modified: 2/26/2008, Yejun Wu
    
    //jump_to_url is the caller or driver, which calls the other functions, such as is_valid, is_adult, adult_jump, child_jump
    function jump_to_url() {
      var age = document.age.box.value;
      if (is_valid(age)){
        if (is_adult(age)){
          adult_jump();
        }else{
          child_jump();
        }
      }else{
        window.alert("Invalid age " + age);
      }
    }
    
    // Some handy functions that simplify the code
    
    function is_adult(age){
        if (age>17){
          return true;
        }else{
          return false;
        }
    }
    
    //prevent invalid input from "evil" users
    function is_valid(age) {
      if (age > 0 && age < 120){
        return true;
      }else{
        return false;
      }
    }
    
    // The main redirection functions
    // selection[0] is the content of 1st radio button, selection[1] is the content of 2nd radio button
    
    function adult_jump() {
      if (document.tool.selection[0].checked==true){ 
        window.location = "http://altavista.com";
      }else{
        if (document.tool.selection[1].checked==true){
          window.location = "http://dmoz.org";
        }else{
          window.alert("You must select a search tool!");
        }
      }
    }
    
    function child_jump() {
      if (document.tool.selection[0].checked==true){ 
        window.location = "http://www.askforkids.com/";
      }else{
        if (document.tool.selection[1].checked==true){
          window.location = "http://kids.yahoo.com";
        }else{
          window.alert("Dear kid, please click a round radio button!");
        }
      }
    }
    
    //-->
    </SCRIPT>
    </HEAD>
    
    <BODY>
    
    <H1>Anytown Public Library Search Tool Selector</H1>
    
    <!--every form has a name-->
    <FORM name=age><B>Please enter your age</B> <INPUT size=10 value=" " name=box> 
    </FORM><B>Select a Search Tool:</B> 
    
    <!--name of form is "tool", the type of input is a radio button, button name is selection-->
    <FORM name=tool>
    <INPUT type=radio name=selection> Web Search Engine <BR>
    <INPUT type=radio name=selection> Web Directory 
    </FORM>
    
    <!--associate onclick to function jump_to_url() -->
    <FORM name=Search>
    <INPUT onclick=jump_to_url() type=button size=10 value=Go! name="go button">
    </FORM>
    
    <HR>
    
    
      </ADDRESS>
      <ADDRESS>&nbsp;</ADDRESS>
    
    <SCRIPT language=JavaScript>
    <!--
    
    var updated = document.lastModified
    document.write("Last modified: "+ updated)
    
    //-->
    </SCRIPT>
    
    </BODY></HTML>

  2.  

  3. #2
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    128
    Member #
    15503
    you could use a switch statement instead. Something like this:

    Code:
    var age = document.age.box.value;
    switch(true){
      case(age <= 17):
        child_jump();
      case(age >= 18 && age <= 39):
        adult_jump();
      case(age >= 40):
        older_jump();
    }
    It's not tested but I think it should work.

  4. #3
    Senior Member shoffman3572's Avatar
    Join Date
    Jul 2008
    Location
    Fullerton, CA
    Posts
    137
    Member #
    16990
    Here's how I would do it - probably not the best way since I'll admit I'm no genius web programmer... Your description of the problem also doesn't cover the ages between 17 and 20? so this code does...

    The html part:

    <form name="mainForm" method="post" onSubmit="return formCheck()">
    Please enter your age: <INPUT size="10" value=" " maxlength="3" name="age"><p>

    please make a selection:<br />
    <INPUT type="radio" name=selection> Web Search Engine <BR>
    <INPUT type="radio" name=selection> Web Director<p>

    <input name="" type="submit">
    </form>

    Then the javascript:

    function formCheck() {

    var age = document.mainForm.age.value;
    if (document.tool.selection[0].checked==false && document.tool.selection[1].checked==false)
    {
    alert ("Please select a search tool!"); return false;
    }
    if (age > 0 && age < 120)
    {
    if ((age >0 && age <18) && document.tool.selection[0].checked=true) {
    window.location = "http://www.askforkids.com/"; }
    if ((age >0 && age <18) && document.tool.selection[1].checked=true) {
    window.location = "http://kids.yahoo.com"; }
    if ((age >17 && age <40) && document.tool.selection[0].checked=true) {
    window.location = "http://altavista.com"; }
    if ((age >17 && age <40) && document.tool.selection[1].checked=true) {
    window.location = "http://dmoz.org"; }
    if (age >40 && document.tool.selection[0].checked=true) {
    window.location = "<over 40 url for selection 0>"; }
    if (age >40 && document.tool.selection[1].checked=true) {
    window.location = "<over 40 url for selection 1"; }
    }
    else
    {
    alert ("Please enter a valid age!");
    return false;
    }
    }

    hope that works for you...


Remove Ads

Posting Permissions

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

Search tags for this page

search tool selector anytown

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com