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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post

    onClick() add id to array

    Im doing some PHP work for this guy, converting an old script to a new site. Here is a sample checkbox used in the script:
    Code:
    <input type=checkbox name=entries[] value=$rid onclick=Check(this,$rid)>
    $rid is the value I want added to the entries[] array when they click the checkbox.

    Here is the javascript
    Code:
    <script>
    function DeleteAllEntries(url)
    {
    	var msg = 'Delete all of your entries?\n\nYes - Click OK\nNo - Click Cancel\n\n'
    			+ 'Note that any new entries received from the\ntime this page was loaded will be deleted too.';
    	if(confirm(msg)) document.location.href = url;
    }
    function NumberOfChecks()
    {
    	var cbs = document.getElementsByName('entries[]');
    	var i, n, num_checks;
    	n = cbs.length;
    	num_checks = 0;
    	for(i=0; i<n; i++)
    	{
    		if(cbs[i].checked) num_checks++;
    	}
    	return num_checks;
    }
    function EnableDisableDeleteButton()
    {
    	var db = document.getElementById('delete_button');
    	if(NumberOfChecks()) db.disabled = false;
    	else db.disabled = true;
    }
    function SetTdStyle(td_id, bgcolor, bordercolor)
    {
    	var td;
    	td = document.getElementById(td_id);
    	td.style.fontFamily = 'Verdana';
    	td.style.fontSize = '12px';
    	td.style.width = '90px';
    	td.style.backgroundColor = bgcolor;
    	td.style.borderWidth = '1px';
    	td.style.borderColor = bordercolor;
    	td.style.borderStyle = 'single';
    }
    function Check(this_cb, td_id)
    {
    	var td;
    	td = document.getElementById(td_id);
    	if(this_cb.checked)
    	{
    		SetTdStyle(td_id, '#aa2222', '#000000');
    	}
    	else
    	{
    		td.setAttribute('bgColor','#FFFFFF');
    		SetTdStyle(td_id, '#ffffff', '#777777');
    	}
    	EnableDisableDeleteButton();
    }
    function CheckAll(this_cb)
    {
    	var cbs = document.getElementsByName('entries[]');
    	var i, n, td, td_id;
    	n = cbs.length;
    	if(this_cb.checked)
    	{
    		for(i=0; i<n; i++)
    		{
    			cbs[i].checked = true;
    			td_id = 'td' + (i+8);
    			td = document.getElementById(td_id);
    			td.setAttribute('bgColor','#B0B0B0');
    			SetTdStyle(td_id, '#B0B0B0', '#000000');
    		}
    	}
    	else
    	{
    		for(i=0; i<n; i++)
    		{
    			cbs[i].checked = false;
    			td_id = 'td' + (i+1);
    			td = document.getElementById(td_id);
    			td.setAttribute('bgColor','#FFFFFF');
    			SetTdStyle(td_id, '#000000', '#000000');
    		}
    	}
    	EnableDisableDeleteButton();
    }
    function ConfirmDelete()
    {
    	if(confirm('Delete the selected entries?'))
    	{
    		document.forms.delete_entries_form.submit();
    	}
    }
    function findPosX(obj){var curleft = 0;if(obj.offsetParent)while(1) {curleft += obj.offsetLeft;if(!obj.offsetParent)break;obj = obj.offsetParent;}else if(obj.x)curleft += obj.x;return curleft;}
    function findPosY(obj){var curtop = 0;if(obj.offsetParent)while(1){curtop += obj.offsetTop;if(!obj.offsetParent)break;obj = obj.offsetParent;}else if(obj.y)curtop += obj.y;return curtop;}
    function Details(dtid,dtdvid)
    {
    	var dta=document.getElementById(dtid);
    	var dtdv=document.getElementById(dtdvid);
    	if(dtdv.style.display=='none')
    	{
    		dtdv.style.display='block';
    		var w;
    		if(window.innerWidth) w = window.innerWidth;
    		else if(document.body.offsetWidth) w = document.body.offsetWidth;
    		else w = 1024;
    		var x = (findPosX(dta)-90);
    		if(x < 10) x = 10;
    		if(x+90 > w) x = w - 90;
    		x = Math.floor(x);
    		dtdv.style.left = x + 'px';
    		dtdv.style.top = (findPosY(dta)+18) + 'px';
    	}
    	else
    	{
    		dtdv.style.display='none';
    	}
    }
    </script>
    I submit the entries array with this code
    Code:
    <form method=POST action=delete.php name=delete_entries_form><input id=delete_button type=submit onclick=javascript:ConfirmDelete(); value=Delete&nbsp;Hit(s) disabled>
    This code works on the old site, but wont work on the new one... I just need the value of the checkbox to be added to the entries array when the checkbox is checked
    -bubbles

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,845
    Thanks
    21
    Thanked 157 Times in 148 Posts
    As far as I know, that checkbox already has a value of $rid and is in the entries[] POST array, regardless if the checkbox is checked or not --- and you should be able to verify this in the PHP script that receives this form...

    In your PHP script, when you add this to your code:

    PHP Code:
    var_dump($_POST['entries']); 
    Do you see the value of the checkbox in the result?
    Last edited by chump2877; 02-17-2007 at 03:38 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,845
    Thanks
    21
    Thanked 157 Times in 148 Posts
    If you;re trying to conditionally add the value of the checkbox to the entries[] array depending on whether or not your checkbox is checked, then perhaps you need something like this (I didn't test this code):

    Code:
    <input type="checkbox" name="whatever" value="myValue" onclick="Check(this,document.delete_entries_form);" />
    
    <script type="text/javascript">
    
    function Check(inputObj,formObj)
    {
        if (inputObj.checked)
        {
            var newInput = document.createElement("input");
            newInput.setAttribute("type","hidden");
            newInput.setAttribute("name","entries[]");
            newInput.setAttribute("value",inputObj.value);
            formObj.appendChild(newInput);    
        }
    }
    
    </script>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


  •  

    Posting Permissions

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