Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: checkbox issues

  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkbox issues

    what would i need to do to get checkbox to correspond to page im submitting to
    heres what i have so far


    [CODE]

    <script type = "text/javascript">
    function newPage(page) {
    if (document.getElementById("chk1").checked) {
    OpenWin = this.open(page,"CtrlWindow","top=80,left=100,screenX=100,screenY=80,width=550,height=460,toolbar=no, menubar=no,location=no, scrollbars=no,resizable=yes");
    return false;
    }
    }


    function closepop() {if (OpenWin != null) OpenWin.close() }
    window.onunload = closepop;

    </script>
    </head>
    <body>
    <form name=”form” id=”form” action=”” method=”post”>
    happy<input type=”text” name=”happy” id=”happy”/>
    sad<input type=”text” name=”sad” id=”sad”/>
    <input type=”submit” value=”submit”/>
    </form>

    <input type = "checkbox" name = "chk1" id = "chk1" onclick = "newPage('randomnewpage.com')">
    <INPUT TYPE=SUBMIT VALUE="submit">

    [CODE]


    the problem with this it always opens the page when i click the checkbox and does not send that values from the form to the page that opens

    what i cant seem to figure out is how to send the values from the form to the new page.
    And when i hit the submit button its opens the submitted form data to the webpage that the checkbox designates instead of opening the new page when i click the checkbox and not waiting for the submit button.

    is there a way i can get the checkbox to do those things or will i need to use something other than javascript for those functions

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,695
    Thanks
    80
    Thanked 4,511 Times in 4,475 Posts
    I don't believe this part of your post:
    And when i hit the submit button its opens the submitted form data to the webpage that the checkbox designates
    When you hit the submit button, it will send the data to the *SAME PAGE* that you are looking at. That is, the form posts to itself.

    Except that you can't use method="post" when submitting to an HTML page. You can only use post for submitting to server side code (PHP/ASP/JSP/etc.).
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,695
    Thanks
    80
    Thanked 4,511 Times in 4,475 Posts
    Questions for you:

    (1) Do you intend to submit the <form> to anything *OTHER* than the popup page designated by the checkbox?

    (2) Do you intend to have more than one checkbox, with each one popping up a different page?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the <form> only goes to the pop up page

    and yes i will have more than one checkbox each to a distinct page, 3 though possibly 4 different pages

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,695
    Thanks
    80
    Thanked 4,511 Times in 4,475 Posts
    Okay, step 1 is to *get* to the different pages with the form data:
    Code:
    <script type = "text/javascript">
    var OpenWin = null;
    function newPage(cb) 
    {
        var form = cb.form;
        form.action = cb.value; 
        OpenWin = window.open("",
                       "CtrlWindow",
                       "top=80,left=100,screenX=100,screenY=80,width=550,height=460,
                        toolbar=no, menubar=no,location=no, scrollbars=no,resizable=yes");
        form.submit();
    }
    
    function closepop() 
    {
        if (OpenWin != null) OpenWin.close();
    }
    window.onunload = closepop;
    </script>
    </head>
    <body>
    <form target="CtrlWindow" method=”get”>
        happy<input type=”text” name=”happy” />
        sad<input type=”text” name=”sad” >
        <label>
            <input type = "checkbox" value="randomnewpage.html" onclick="newPage(this);"/>
            ONE
        </label>
        <label>
            <input type = "checkbox" value="anotherpage.html" onclick="newPage(this);"/>
            TWO
        </label>
        <label>
            <input type = "checkbox" value="stillmore.html" onclick="newPage(this);"/>
            THREE
        </label>
    </form>
    Try that.

    Change your popup specifcation from location=no to location=yes and you'll be able to see that the information in the <form> (the values of happy and sad) are being passed in the query string to the popup.

    The next part is learning how to read the query string values via JavaScript so you can use those values in the popup.

    Give me an example of what you would do with them.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, actually ive decided to change the layout of the website for now until i get a better grasp on javascript. its helpful though since it gives me an idea of where i need to get in understanding of javascript at least.

    thanks again


  •  

    Posting Permissions

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