SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2002
    Location
    Madison, WI
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem passing checkbox values back to window.opener

    Hi,

    I have a button on page A the pops up a form on page B. From page B I want the user to be able to select some checkboxes and populate a field back in page A with the value of the checkboxes. I can't quite get it to work; In the field on page B I want to populate, I get "undefined".

    Code:
       
       <script language="javascript">
       function addQuickLinks() {
      // name of the checkboxes
       thisFormField = window.document.selQuickLinks.ql;
       origWindow = window.opener;
      // field on page A that I want to populate
       origField = origWindow.document.SendDocLinks.linkID;
       origField.value = thisFormField.value;
       window.close();
       
       }
       </script>
       <form name="selQuickLinks" method="post" action="">
      
     <input type="checkbox" name="ql" value="63" id="ql63" /><label for="ql63">American Indian Chamber of Commerce of WI</label><br />
      
     <input type="checkbox" name="ql" value="47" id="ql47" /><label for="ql47">Associations, Directory of</label><br />
      
     <input type="checkbox" name="ql" value="52" id="ql52" /><label for="ql52">Build Your Business (Wisconsin.gov)</label><br />
      
     <input type="checkbox" name="ql" value="41" id="ql41" /><label for="ql41">Bus.Assist.Procurement Ctr-MATC (getting gov. contracts)</label><br />
      
      <input type="button" value="Add Now" onClick="addQuickLinks();" class="btn" /> 
      
      </form>
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    Versa Studio
    ExpressionEngine experts
    bas (at) versa studio dot com

  2. #2
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have more than one element named ql, so document.selQuickLinks.ql.value is undefined. document.selQuickLinks.ql[0].value would give you 63, document.selQuickLinks.ql[1].value would give you 47, etc.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2002
    Location
    Madison, WI
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see. Is there some way to agreggate the values of all the checkboxes document.selQuickLinks.ql[0].value...[x].value, and dump them into the form field?

    Thanks.
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    Versa Studio
    ExpressionEngine experts
    bas (at) versa studio dot com

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2002
    Location
    Madison, WI
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I figured it out.

    FYI, this code corresponds to a form with a bunch of checkboxes with the same name, like this:

    <input type="checkbox" name="ql" value="51" />click for 51<br />
    <input type="checkbox" name="ql" value="56" />click for 56<br />
    <input type="checkbox" name="ql" value="59" />click for 59<br />
    <input type="button" onclick="aggregateLinkIDs()" name="a" />

    function aggregateLinkIDs() {
    // aggregate values of all checkboxes named ql. Starts with value of 0 to keep a proper comma-delimited list
    myString = "0";
    var i = 0;
    while(i<window.document.selQuickLinks.ql.length)
    {
    if(window.document.selQuickLinks.ql[i].checked)
    {
    myString+=","+window.document.selQuickLinks.ql[i].value;
    }
    i++;
    }
    addQuickLinks();
    }
    function addQuickLinks() {
    // pass the value from previous function in to the linkID text field on calling page, and close window
    origWindow = window.opener;
    fieldToFill = origWindow.document.SendDocLinks.linkID;
    fieldToFill.value = myString;
    fieldToFill.style.backgroundColor='gray';
    window.close();

    }
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    Versa Studio
    ExpressionEngine experts
    bas (at) versa studio dot com


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
  •