Re: [Proto-Scripty] Tactical Advice: Many rows, one checkbox per row
Sorry for the mess I produced. Of course all this stuff with _checked array is not necessery if you want send AjaxRequest immediatly after checkbox click - just extract the clicked item and send all needed data including checkbox state as you do. -wz Hi I wrote a routine (not sure if it fits exactly what you need), yet it presents the logic and maybe you will be able to fit in your code. Notice it is not tested and uses prototype 1.7. It is wrote as clousure yet you may transfer it easly into Object Literal or class or something. Ah - and there is only one observer - on form: Here you are: (function() { var _checked = undefined; document.observe(dom:loaded, function() { // select all checked ckeckboxes _checked = $('formId').select('input[checked]').pluck('value'); //register observer on form click $('formId').on('click', _onClick); }); function _onClick(event, element) { var isUnchecked = undefined; //if clicked element is input if (element.tagName.toLowerCase() == 'input') { // here we find out if our checkbox was checked or not at time of page loaded (isUnchecked == true shows it was checked and now is not) isUnchecked = _checked.indexOf(element.value) -1 ? true : false; // send Ajax request _sendAjaxRequest(element, isUnchecked); } } function _sendAjaxRequest(element, isUnchecked) { new Ajax.Request('url', { method: 'post', parameters: { here you serialize your checkbox (element) manually}, onSuccess: function(transport) { var response = transport.responseText.evalJSON(); .. }, onComplete: function() { } }); } })(); Hope it helps -wz I just drastically shortened this down... I'm now serializing the data manually with: strSerialize = active_record= +cbValue +state= +strState; Which produces: active_record=5state=checked On the server side I can easily get the two values with $_POST... so far perfect... I've deleted all the hidden fields... Now when you click on the checkbox, onchange does all the work and since I enable/disable the form, only one submission happens at a time... exactly as we want it... Working perfectly... Thanks for the help! On Thu, Apr 26, 2012 at 10:51 AM, Phil Petree phil.pet...@gmail.com mailto:phil.pet...@gmail.com wrote: I got it working... here's where I am so far: 1) at the top of the form I created a hidden input called 'active_record' which holds the $('id') of the row in progress 2) each row has input type=hidden name=$record_num value='' input type=checkbox value=$record_num checked='checked/unchecked' onchange='updateRow(this.id http://this.id, this.value);' 3) updateRow(cbID, cbValue) {} wherein I set the value of the hidden $record_num with checked || unchecked and active_record with the cbValue and then call my ajax function which serializes the form and makes the call. 4) oncomplete: I clear the two hidden inputs. In my php code I can check my $_POST: $record = $_POST['active_record']; $value = $_POST[$record]; error_log(record num is: $record and is set to $value); Problem: I'm still sending all the rows where the type=checkbox has checked=checked but I'm not processing those. Has no real impact on performance right now but with 1000's of users and frequent approval/disapprovals, it will unnecesssarily suck up bandwidth and time. Any idea how to serialize just one field? Afterall, all I really need to do is send the checked/unchecked from the active_records hidden input... -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
Try it passing cb1 into a function as cbValue and then $(cbValue).checked... On Apr 27, 2012 1:46 AM, Wojtek Zadora woj...@studioatrium.pl wrote: Well, I tested it and in my case having input type=checkbox name=1 value=1 id=cb1 console.log($('cb1').checked); - returns false console.log($('cb1').**readAttribute('checked')); - returns null While input type=checkbox name=2 value=2 id=cb2 checked=checked console.log($('cb2').checked); - returns true console.log($('cb2').**readAttribute('checked')); - returns checked -wz How do you get the checked state of a single checkbox? $('cbID').checked doesn't work... also tried $F('cbID').checked in the following function, the alert comes back with undefined cdValue is the id of the checkbox... function saveChange(cbValue) { var strState; var cbState; // get the value of the checkbox // we do it here incase this is called // from the onchange attached to the select cbState = $(cbValue).checked; alert(cbState); if( cbState == checked ) strState = checked; else strState = unchecked; } -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@** googlegroups.com prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+** unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/prototype-scriptaculous?**hl=enhttp://groups.google.com/group/prototype-scriptaculous?hl=en . -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@** googlegroups.com prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+** unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/prototype-scriptaculous?**hl=enhttp://groups.google.com/group/prototype-scriptaculous?hl=en . -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
$(cbValue).checked returns boolean (true|false) and you compare it to string: if( cbState == checked ) simply strState = (cbState == true) ? checked : unchecked; -wz Try it passing cb1 into a function as cbValue and then $(cbValue).checked... On Apr 27, 2012 1:46 AM, Wojtek Zadora woj...@studioatrium.pl mailto:woj...@studioatrium.pl wrote: Well, I tested it and in my case having input type=checkbox name=1 value=1 id=cb1 console.log($('cb1').checked); - returns false console.log($('cb1').readAttribute('checked')); - returns null While input type=checkbox name=2 value=2 id=cb2 checked=checked console.log($('cb2').checked); - returns true console.log($('cb2').readAttribute('checked')); - returns checked -wz How do you get the checked state of a single checkbox? $('cbID').checked doesn't work... also tried $F('cbID').checked in the following function, the alert comes back with undefined cdValue is the id of the checkbox... function saveChange(cbValue) { var strState; var cbState; // get the value of the checkbox // we do it here incase this is called // from the onchange attached to the select cbState = $(cbValue).checked; alert(cbState); if( cbState == checked ) strState = checked; else strState = unchecked; } -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us http://script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com mailto:prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com mailto:prototype-scriptaculous%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us http://script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com mailto:prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com mailto:prototype-scriptaculous%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
Dang it... I knew it had to be something stpid!!! LOL Thanks! Its 4a here, I'm gonna get some sleep. On Apr 27, 2012 4:10 AM, Wojtek Zadora woj...@studioatrium.pl wrote: $(cbValue).checked returns boolean (true|false) and you compare it to string: if( cbState == checked ) simply strState = (cbState == true) ? checked : unchecked; -wz Try it passing cb1 into a function as cbValue and then $(cbValue).checked... On Apr 27, 2012 1:46 AM, Wojtek Zadora woj...@studioatrium.pl wrote: Well, I tested it and in my case having input type=checkbox name=1 value=1 id=cb1 console.log($('cb1').checked); - returns false console.log($('cb1').readAttribute('checked')); - returns null While input type=checkbox name=2 value=2 id=cb2 checked=checked console.log($('cb2').checked); - returns true console.log($('cb2').readAttribute('checked')); - returns checked -wz How do you get the checked state of a single checkbox? $('cbID').checked doesn't work... also tried $F('cbID').checked in the following function, the alert comes back with undefined cdValue is the id of the checkbox... function saveChange(cbValue) { var strState; var cbState; // get the value of the checkbox // we do it here incase this is called // from the onchange attached to the select cbState = $(cbValue).checked; alert(cbState); if( cbState == checked ) strState = checked; else strState = unchecked; } -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
Well, that didn't work... input type='checkbox' id='1' name='approved' onclick=saveChange(1); checked='checked'/ select id='ajMode_1' name='mode' onchange=saveChange(1); option value='read_write' selected='selected'Send and Receive/option option value='read_only'Receive Only/option /select function saveChange(cbValue) { var strSerialize; var strState; var strMode; var strSelectName = ajMode_ +cbValue; var cbState; // get the value of the checkbox // we do it here incase this is called // from the onchange attached to the select cbState = $(cbValue).checked; strState = (cbState == true) ? checked : unchecked; // get the value from the selected rw_mode strMode = $F(strSelectName); // serialize the data and send to the server for saving strSerialize = record= +cbValue +state= +strState +mode= +strMode; alert(strSerialize); // always shows strState as unchecked autosave(strSerialize); // make the ajax call } On Fri, Apr 27, 2012 at 4:10 AM, Wojtek Zadora woj...@studioatrium.plwrote: $(cbValue).checked returns boolean (true|false) and you compare it to string: if( cbState == checked ) simply strState = (cbState == true) ? checked : unchecked; -wz Try it passing cb1 into a function as cbValue and then $(cbValue).checked... On Apr 27, 2012 1:46 AM, Wojtek Zadora woj...@studioatrium.pl wrote: Well, I tested it and in my case having input type=checkbox name=1 value=1 id=cb1 console.log($('cb1').checked); - returns false console.log($('cb1').readAttribute('checked')); - returns null While input type=checkbox name=2 value=2 id=cb2 checked=checked console.log($('cb2').checked); - returns true console.log($('cb2').readAttribute('checked')); - returns checked -wz How do you get the checked state of a single checkbox? $('cbID').checked doesn't work... also tried $F('cbID').checked in the following function, the alert comes back with undefined cdValue is the id of the checkbox... function saveChange(cbValue) { var strState; var cbState; // get the value of the checkbox // we do it here incase this is called // from the onchange attached to the select cbState = $(cbValue).checked; alert(cbState); if( cbState == checked ) strState = checked; else strState = unchecked; } -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
On 27 April 2012 09:12, Phil Petree phil.pet...@gmail.com wrote: Its 4a here, I'm gonna get some sleep. On 27 April 2012 10:04, Phil Petree phil.pet...@gmail.com wrote: Well, that didn't work... not enough sleep! input type='checkbox' id='1' not a legal ID - must start with a letter onclick=saveChange(1); 1 is a number, '1' is a string function saveChange(cbValue) a better name for the parameter would be cbID Dave -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] stupid checkbox question
Dave, you're a gentleman and a scholar... The id was irrelevant because in the original pass I was passing in this.checked but then someone suggested we allow them to change the mode as well so then I couldn't use this.checked with an onchange fired via a select and by then it was wy to late into the wee hours to see what was wrong. Thanks! On Fri, Apr 27, 2012 at 5:47 AM, Dave Kibble davekib...@gmail.com wrote: On 27 April 2012 09:12, Phil Petree phil.pet...@gmail.com wrote: Its 4a here, I'm gonna get some sleep. On 27 April 2012 10:04, Phil Petree phil.pet...@gmail.com wrote: Well, that didn't work... not enough sleep! input type='checkbox' id='1' not a legal ID - must start with a letter onclick=saveChange(1); 1 is a number, '1' is a string function saveChange(cbValue) a better name for the parameter would be cbID Dave -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.