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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to pass the checkbox values when opening a new window

    I have a form that has checkboxes and I need to open a new window and pass the value of the checkboxes in the url as a parameter. My next page is an asp page that looks for the value in the querystring for the SQL query on that page.

    Currently my code to open the new window looks like this, this is an .asp page:

    <A HREF="show_line_items.asp?id=<%ID%>" ONCLICK="window.open('show_line_items.asp?ID=<%=id%>'); return false">View Line Items</a>

    I need to add the values from chk_SOID the resulting url needs to look like this - http://mysite.com/show_line_items.as...lueof_chk_SOID is equal to.

    I have no idea how to do this. I have scoured the web and I can't find an example of how to do, couldn't find anything in any of my javascript books. Figured this would be easy for someone with a lot of Javascript experience. My Javascript is limited to what I can copy and make small modifications to. If anyone can point me to an example or provide one I would greatly appreciate it.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Code:
    <A HREF="show_line_items.asp?id=<%ID%>" ONCLICK="return doOpen('show_line_items.asp', '<%=id%>');">View Line Items</a>
    ...
    function doOpen(page, id){
      var w = window.open(page + '?id=' + id + '&SOID=' + document.forms[0].chk_SOID.value, "lineItemsWin", "width=600, height=400, resizable=1");
      w.focus();
      return false;
    }
    or I think you want to pass the value of the checkbox only if it's checked.
    Code:
    function doOpen(page, id){
      var soid = (document.forms[0].chk_SOID.checked) ? document.forms[0].chk_SOID.value : "";
      var w = window.open(page + '?id=' + id + '&SOID=' + soid, "lineItemsWin", "width=600, height=400, resizable=1");
      w.focus();
      return false;
    }

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not passing the checkbox values

    I tried this code and it is still only passing the ID and not adding the SOID=andwhateverischecked to the url. It is not even adding the &SOID=, the url looks like this: http://mysite.com/show_line_items.asp?id=1-120674099. It is opening a new window.

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This will work for any number of checkboxes:
    Code:
    function sendIt(page,id)
    {
    var myform = document.getElementsByTagName('form')[0]; //first form on page
    
    var inputs = myform.getElementsByTagName('input');
    var i;
    
    for(i=0;i<inputs.length;i++)
    {
    if((inputs[i].type == 'checkbox') && (inputs[i].checked == true))
    {
    var soid = page + '?id=' + id + '&SOID=' + inputs[i].value;
    var w = window.open(soid, "lineItemsWin", "width=600, height=400, resizable=1");
    w.focus();
    return false;
    }
    }
    }

  • #5
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not working, maybe I have something wrong?

    Here is the line that calls the function:

    <TD bgcolor=<%=str_BgColor%>><A HREF="quote_header_info.asp?id=<%=ID%>" ONCLICK="return sendIt('quote_header_info.asp', '<%=ID%>');">Go</a></td>

    It does not open a new page, it looks like it just sending it to the url in the A HREF tag. It looks like this: http://mysite.com/testing/quote_head...id=1-124689347

    For some reason the url does not display correctly the text after testing is /quote_header_info.asp?id=1-124689347

    And the script you so kindly posted:
    <script Language="JavaScript">
    <!--

    function sendIt(page,id)
    {
    var myform = document.getElementsByTagName('form')[0]; //first form on page

    var inputs = myform.getElementsByTagName('input');
    var i;

    for(i=0;i<inputs.length;i++)
    {
    if((inputs[i].type == 'checkbox') && (inputs[i].checked == true))
    {
    var soid = page + '?id=' + id + '&SOID=' + inputs[i].value;
    var w = window.open(soid, "lineItemsWin", "width=600, height=400, resizable=1");
    w.focus();
    return false;
    }
    }
    }
    //-->
    </script>
    Last edited by jenab; 01-18-2006 at 09:31 PM.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    The page might have javascript errors as it loads causing subsequent function calls or statements not to work. Check the Javascript Console after the page loads to see if there's any error.

  • #7
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No error

    I loaded the page and there is no error icon showing.

    Does the code look right? Does the syntax look right? I am thinking it is probably one little thing throwing the whole thing off.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Put an alert inside the function to verify that it is being called at all.


  •  

    Posting Permissions

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