SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    returning checkbox information

    OK, I am trying to return a string of email addresses pulled from list stored in the database. The result will be store in a single column of comma delimited values ( I didn't design the darn thing ). Anyway, I've tried about as many ways as I can think of and followed all of the examples I could find and nothing works. I can return an explicitly set value - so I know I am getting here, but am stuck. I press the save button and nothing happens. It just sits there and mocks me. I've attached an image of what I am trying to accomplish, if that is of any use. -Bob


    ------ Following is the complete program -- any help would be appreciated.

    <html>
    <head>
    <script type="text/javascript">
    <!--
    function returnValue()
    {

    var que = unescape(location.search);
    var que = que.substring(1, que.length);
    var que = que.split("&");
    var querystring = new Array();
    var loop = 0;
    while (loop < que.length) {
    var inter = que[loop].split("=");
    var inter2 = inter[1];
    var inter3 = inter[0]
    que[loop] = inter2;
    querystring[inter3] = inter2
    loop = loop + 1;
    }
    var form = querystring['form'];
    var field = querystring['field'];

    // This works BEGIN PROBLEM CODE
    var arg = "bob.peele@oracle.com, boss.man@oracle.com";

    // Many things that don't seem to work...
    //var arg = document.cb_form.cb_item[3].value;
    //var arg = document.cb_form.cb_item[3];
    //var arg = document.forms[\'cb_form\'].cb_item[3].value;
    //var arg = document.forms[\'cb_form\'].cb_item[3];
    //var cbs = document.getElementById("cb_form").cb_item;

    // What I'd really like to work (except for the extra trailing comma-space)
    //var arg = "";
    //for (var i=0;i<cbs.length;i++) {
    // if(cbs[i].checked){
    // arg+=cbs[i].value+", ";
    // }
    //}
    // ---------------END PROBLEM CODE ---------------------------

    // put arg in form.field of calling program and close popup list of values
    eval("opener.document.forms['" + form + "']."+field+".value = arg ;");
    self.close();
    }
    //-->
    </script>
    </head>
    <body>
    <center>
    <h3><i>DT_ALERT_EMAIL LOV</i></h3>
    <?php
    include('../lib/db_functions.php');

    $sql = "select au_firstname||' '||au_lastname DESCR, "
    ." au_email VAL"
    ." from ads_users "
    ." where au_org in ( select ao_id from ads_organisations where ao_name = 'TDS' ) "
    ." order by au_lastname, au_firstname";

    $connection = tdsweb_connection('TEST');
    if (!$connection) {
    $err = oci_error();
    $msg = htmlentities($err['message']);
    print "<b><font color=red>".$msg."</font></b><br>\n";
    } else {
    $cursor = oci_parse($connection, $sql);
    if (!$cursor) {
    $err = oci_error();
    $msg = htmlentities($err['message']);
    print "<b><font color=red>".$msg."</font></b><br>\n";
    } else {
    $execute_ok = oci_execute($cursor);
    if (!$execute_ok) {
    $err = oci_error();
    $msg = htmlentities($err['message']);
    print "<b><font color=red>".$msg."</font></b><br>\n";
    }
    }
    }

    $email_list = explode(',', $_REQUEST['orig_value']);
    print "<input type=button name=action value=Cancel onclick='window.close()'>";
    print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    print "<input type=button name=action value=Save onclick='returnValue()'>";
    print "<form name=cb_form action=".$_SERVER[PHP_SELF]." method=post>";
    print "<table>\n";
    $nbr_cols = 0;
    print "<tr>";
    while ($row = oci_fetch_assoc($cursor)) {
    if ( $nbr_cols > 2 ) {
    print "</tr><tr>";
    $nbr_cols = 0;
    }
    $val = trim($row['VAL']);
    $desc = $row['DESCR'];
    print "<td>\n";
    if ( email_in_list($val, $email_list) ) {
    print "<input type=checkbox name=cb_item value='".$val."' checked >".$desc."\n";
    } else {
    print "<input type=checkbox name=cb_item value='".$val."' >".$desc."\n";
    }
    print "</td>\n";
    $nbr_cols++;
    }
    print "</tr>\n";
    print "</table>\n";
    print "</form>\n";

    function email_in_list( $s, $a ) {
    for ( $i=0; $i<sizeof($a)-1; $i++ ) {
    if ( trim(strtolower($a[$i])) == trim(strtolower($s)) ) { return true; break; }
    }
    return false;
    }
    ?>
    </center>
    </body>
    </html>
    Attached Images Attached Images

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see that your check boxes all have the same name. That needs changing for starters.

    Also, are you simply trying to get all check boxes that have been checked and get their values?

    Code:
    function returnValue()
    {
    	var arg;
    
    	var elements = document.getElementsByTagName('INPUT');
    	for(var i = 0; i < elements.length; i++)
    	{
    		if(elements[i].type == 'checkbox')
    		{
    			if(i != elements.length) // might need to change this to if(i != elements.length-1)
    				arg+=elements[i].value+', ';
    			else
    				arg+=elements[i].value;
    		}
    	}
    
    	// do something with your arg attribute.
    }
    This will loop through all the checkboxes in the page, if you want to get all the checkboxes within a div or other element just simply change document.getElementsByTagName to

    Code:
    var myElement = document.getElementById('CheckBoxContainer');
    var elements = myElement.getElementsByTagName('INPUT');
    Gav


  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I have read, if checkboxes use the same name the values are returned as an array. That seems entirely appropriate for this application:

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Got It!

    I don't know why this works and the other code doesn't, but it did it. Does the var "obj" signify something special? Anyway - that's to all for looking.
    -Bob
    ------------------------------------------

    var obj = document.cb_form.cb_item;
    var arg = "";
    var check_count = 0;
    var j = 0;
    for (var i = 0; i < obj.length; i++) {
    if (obj[i].checked) {
    check_count++;
    if ( j == 0 ) { arg += obj[i].value; }
    else { arg += ", "+obj[i].value; }
    j++;
    }
    }


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
  •