Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Function with URL call

  1. #1
    Join Date
    Nov 2011
    Location
    NJ
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Function with URL call

    How do I get the function below to automatically take visitors to different URLs if the value they enter matches man or woman. E.g If it matches man, it takes them to URL A while Woman takes them to URL B

    Code:
    <script type='text/javascript'>
    
    var urlMap = {
      'man' : 'http://some.domain/something',
      'woman' : 'http://some.domain/something/else',
      'cat' : 'http://whatever.you.want/more/here',
      'dog' : 'http://the.last.example/for/now'
    };
    
    
    function lookupUrl( choice ) {
      var url = urlMap[ choice ];
      if (url === undefined) throw "Improper input!";
      return url;
    }
    
    
    
    </script>
    
      <form>
    Letters Only: <input type='text' id='letters'/>
    <input type='button' 
        onclick="isAlphabet(document.getElementById('letters'), 'Letters Only Please')"
        value='Check Field' />
    </form>
    Please help me, How do I get it to work?
    Last edited by jscheuer1; 11-09-2011 at 08:00 AM. Reason: Format

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Your function isAlphabet is not defined.
    But why shouldn't you use a selectbox for what you want? It'll save you the effort of prompting the users who put something in the box that you don't want at all.
    Here's something you could use. The URLS are just examples. If you want to open the URLS in an iframe, choose the 4 first options. If you want them to open in a new window, choose the last 4 options:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
     
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.0001)">
    <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.0001)">
     
    <title></title>
     
    <meta http-equiv="imagetoolbar" content="no" >
    <script type="text/javascript">
    //This script enables execution of scripts by putting them in the options of selectboxes (if the text of a given option corresponds with the contents of a given script, then the script is executed when the option is clicked on).
    function load_script_container()
    {var div_node=document.createElement('div');
    div_node.setAttribute("id", "script_container");
    document.body.appendChild(div_node);}
    window.onload=load_script_container
    
    function javascript_in_selectbox(which_box) {
    var optionValue=document.getElementById(which_box).options[document.getElementById(which_box).selectedIndex].value;
    if (optionValue=="none") {}
    else {
    var script_inside_selectbox_option = document.createElement('script');
    script_inside_selectbox_option.type = 'text/javascript';
    script_inside_selectbox_option.text = optionValue;
    while(document.getElementById("script_container").firstChild)
    {document.getElementById("script_container").removeChild(document.getElementById("script_container").firstChild);}
    document.getElementById("script_container").appendChild(script_inside_selectbox_option);
    }
    }
    </script>
    
    <script type="text/javascript">
    document.write('<div id="select_div" style="display:inline"><\/div>')
    function write_to_div(url)
    {
    document.getElementById("select_div").innerHTML="<div style='position: absolute; left:100px; top: 100px; right: 100px; bottom: 100px'><div onclick='document.getElementById(\"select_div\").innerHTML=\"\"' style='float: right; cursor: pointer; margin-top: -17px; font-family: verdana; font-size:13px; padding-left:3px; padding-right:3px; color: white; background: black'>X<\/div><iframe style='position: absolute; width: 100%; height: 100%' src="+url+"><\/iframe><\/div>"
    }
    </script>
    </head>
    
    <body>
    
    Make your choice&nbsp;
    <!--[if IE]> <div style="position: relative; width:132px; overflow:hidden; border: 1px solid black"> <![endif]-->
    <!--[if !IE]><!--> <div> <!--<![endif]--> 
    <select name="something" id="something" style="position:relative;width:132px;" onchange="javascript_in_selectbox('something');selectedIndex=0;this.blur();if (/*@cc_on!@*/false){this.style.width='132px'};" onblur="if (/*@cc_on!@*/false){this.style.width='132px'}" onmousedown="if (/*@cc_on!@*/false){this.style.width='220px'}" >
    <option value="none" selected style="color:darkred" class="first_option" >Make your choice</option>
    
    <option value="write_to_div('http://www.dynamicdrive.com')" >Man</option>
    <option value="write_to_div('http://www.hostsearch.com')">Woman</option>
    <option value="write_to_div('http://www.dreamtemplate.com')">Cat</option>
    <option value="write_to_div('http://www.dailymotion.com')">Dog</option>
    
    <option value="window.open('http://www.dynamicdrive.com')" >Man (opens in new window)</option>
    <option value="window.open('http://www.hostsearch.com')" >Woman (opens in new window)</option>
    <option value="window.open('http://www.dreamtemplate.com')" >Cat (opens in new window)</option>
    <option value="window.open('http://www.dailymotion.com')" >Dog (opens in new window)</option>
    
    </select>
    </div> 
    
    </body>
    
    </html>
    Arie Molendijk.

  3. #3
    Join Date
    Nov 2011
    Location
    NJ
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Why it's an input

    Arie, it is an input because me clients will all Be given access codes which will help them access their specific pages to see their subscriptions. Please help me. thanks

  4. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Do you have a link to the problematic page, or the source of the complete page?
    Arie.

  5. #5
    Join Date
    Nov 2011
    Location
    NJ
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trying it before using it

    I'm trying it first before Implementing proper. you understand Exactly what I need But the difference is that the client will enter a given code; then if matches A (hidden) it takes them to where they'll see their receipt and subscription details.

  6. #6
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    OK, but give me at least the function isAlphabet then. It's invoked on your page, but I don't know what it does. It should be defined somewhere.
    Arie.

  7. #7
    Join Date
    Nov 2011
    Location
    NJ
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How Do I get it to work.

    Thanks for your patience and help. Someone got me confused with that one bro, and I'm still a learner. What if we add this line

    var theUrl = lookupUrl(document.getElementById('letters').value);

    You're a senior developer, make what ever changes that you think are necessary.
    How do we get it to work.
    Please help me

  8. #8
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    This would be a solution in its simplest form:
    Code:
    <head>
    
    <script type="text/javascript">
    function access()
    {
    if(document.getElementById('letters').value=='man')location.href='http://www.google.com'
    else if(document.getElementById('letters').value=='woman')location.href='http://www.dynamicdrive.com'
    else if(document.getElementById('letters').value=='cat')location.href='http://www.youtube.com'
    else if(document.getElementById('letters').value=='dog')location.href='http://www.dailymotion.com'
    else alert('Access denied. Try again.')
    }
    </script>
    
    </head>
    
    <body>
    <form>
    Letters Only: <input type='text' id='letters'></input>
    <input type='button' onclick='access()' value='Check Field' ></input>
    </form>
    </body>
    You can elaborate it further.
    Arie.

  9. #9
    Join Date
    Nov 2011
    Location
    NJ
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    molendijk, I sincerely appreciate your help. It's not confusing in anyway and it's awesome. Thanks again!!

  10. #10
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

Bookmarks

Posting Permissions

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