Results 1 to 3 of 3

Thread: Boy or Girl

  1. #1
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Boy or Girl

    Ok, I made a form to select between Boy or Girl and direct between pages, but I'm not sure how the JavaScript should go, I have nothing. Heres my form.

    Code:
    <form method="post" action="jscript/boygirl.js">
    Boy <input name="boygirl" value="boy" type="radio"><br>
    Girl <input name="boygirl" value="girl" type="radio"><br>
      <br>
      <input name="submit_boygirl" value="Continue"
     type="submit"></form>
    All I need is a little direction, specifically I want to know how to make it compare what it gets submitted through the form. I'm not sure how you do that. I was trying to use getSelectedRadio, and getSelectedRadioValue. But I couldn't figure it out.

    Thanks,
    Tim

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The real value of something like this would be to redirect server side (where forms have their real power) on the basis of the submitted value with no javascript involved. However, here is an interesting example of something that could be done with javascript:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>BOY GIRL</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function getQval(n, m) {
    /*my n=name, m=searchString(optional)*/
    if(!arguments[0]||typeof n!='string')
    return null;
    var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=arguments[1]?m:location.search;
    return (m=r.exec(m))? unescape(m[1]) : null;
    }
    function showHide(v){
    var c=v=='boy'? 'girl' : v=='girl'? 'boy' : 'boygirl';
    document.write('<style type="text/css">.'+c+' {display:none;}<\/style>')
    if(v)
    document.title=v.toUpperCase();
    }
    showHide(getQval('boygirl'));
    </script>
    </head>
    <body>
    <form action="#">
    <div class="boy girl">
    Boy <input name="boygirl" value="boy" type="radio"><br>
    Girl <input name="boygirl" value="girl" type="radio"><br>
      <br>
      <input value="Continue" type="submit">
    </div>
    </form>
    <div class="boygirl">
    <div class="boy">It's a Boy!</div>
    <div class="girl">It's a Girl!</div>
    </div>
    </body>
    </html>
    Last edited by jscheuer1; 08-24-2007 at 06:06 PM. Reason: correct syntax
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    The real value of something like this would be to redirect server side (where forms have their real power) on the basis of the submitted value with no javascript involved. However, here is an interesting example of something that could be done with javascript:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>BOY GIRL</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function getQval(n, m) {
    /*my n=name, m=searchString(optional)*/
    if(!arguments[0]||typeof n!='string')
    return null;
    var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=arguments[1]?m:location.search;
    return (m=r.exec(m))? unescape(m[1]) : null;
    }
    function showHide(v){
    var c=v=='boy'? 'girl' : v=='girl'? 'boy' : 'boygirl';
    document.write('<style type="text/css">.'+c+' {display:none;}<\/style>')
    if(v)
    document.title=v.toUpperCase();
    }
    showHide(getQval('boygirl'));
    </script>
    </head>
    <body>
    <form action="#">
    <div class="boy girl">
    Boy <input name="boygirl" value="boy" type="radio"><br>
    Girl <input name="boygirl" value="girl" type="radio"><br>
      <br>
      <input value="Continue" type="submit">
    </div>
    </form>
    <div class="boygirl">
    <div class="boy">It's a Boy!</div>
    <div class="girl">It's a Girl!</div>
    </div>
    </body>
    </html>
    Interesting. So the content is there all along, JavaScript just reveals it? How should I do what I wanted?

    Code:
    Boy <input onclick="parent.location='boys.html';"
     name="boyorgirl" value="boy1" type="radio"><br>
    Girl <input onclick="parent.location='girls.html';"
     name="boyorgirl" value="girl1" type="radio">
    I made something up, it seems to work.
    Last edited by TimFA; 08-24-2007 at 06:44 PM. Reason: Got something.

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
  •