
The normal way of reading a form value is: var city= $("[name='city']").val(); //using the element's name or var city= $("#city").val(); //using the element's ID Question: What if you had several checkboxes e.g. <input type='checkbox' name='cities[]' value='Kisumu' /> <input type='checkbox' name='cities[]' value='Mombasa' /> <input type='checkbox' name='cities[]' value='Nairobi' /> And you want to find out which one's the user clicked on, assuming that the user can choose more than one. var city= $("[name='cities[]']").val(); //is not working

How about giving them a class attribute and adding something similar to: $(".class_name").click(function(){ //use $(this) to get the exact checkbox that was clicked $(this).attr("value"); //This will get the value of the checkbox }); HTH Thanks and Regards, Erick Njenga Nyachwaya, M: +254-725-008-790 <http://www.facebook.com/ErickNjenga> <http://www.twitter.com/ErickNjenga>

+1 On Tue, Sep 6, 2011 at 10:11 AM, Erick Njenga <eriknjenga@gmail.com> wrote:
How about giving them a class attribute and adding something similar to:
$(".class_name").click(function(){
//use $(this) to get the exact checkbox that was clicked
$(this).attr("value"); //This will get the value of the checkbox
});
HTH
Thanks and Regards, Erick Njenga Nyachwaya, M: +254-725-008-790
<http://www.facebook.com/ErickNjenga> <http://www.twitter.com/ErickNjenga>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Maybe I should have explained my goal; to 'harvest' all form data when the user clicks the submit button, then submit them using jQuery powered AJAX. If the user checked 2 out of the 3 checkboxes, will jQuery 'remember' the ones the user checked? On Tue, Sep 6, 2011 at 10:24 AM, Chris Mwirigi <mwirigic@gmail.com> wrote:
+1
On Tue, Sep 6, 2011 at 10:11 AM, Erick Njenga <eriknjenga@gmail.com>wrote:
How about giving them a class attribute and adding something similar to:
$(".class_name").click(function(){
//use $(this) to get the exact checkbox that was clicked
$(this).attr("value"); //This will get the value of the checkbox
});
HTH
Thanks and Regards, Erick Njenga Nyachwaya, M: +254-725-008-790
<http://www.facebook.com/ErickNjenga><http://www.twitter.com/ErickNjenga>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*

var values = $("input[name='cities[]']").serializeArray(); will give you a JS object from the selected checkboxes, you can now convert the object to json and pass to your ajax method. you can also serialize the entire form and handle the posted data on the server side script maybe you should post the whole form. might be easier to understand what you exactly want to achieve. On Tue, Sep 6, 2011 at 10:29 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
Maybe I should have explained my goal; to 'harvest' all form data when the user clicks the submit button, then submit them using jQuery powered AJAX.
If the user checked 2 out of the 3 checkboxes, will jQuery 'remember' the ones the user checked?
On Tue, Sep 6, 2011 at 10:24 AM, Chris Mwirigi <mwirigic@gmail.com> wrote:
+1
On Tue, Sep 6, 2011 at 10:11 AM, Erick Njenga <eriknjenga@gmail.com>wrote:
How about giving them a class attribute and adding something similar to:
$(".class_name").click(function(){
//use $(this) to get the exact checkbox that was clicked
$(this).attr("value"); //This will get the value of the checkbox
});
HTH
Thanks and Regards, Erick Njenga Nyachwaya, M: +254-725-008-790
<http://www.facebook.com/ErickNjenga><http://www.twitter.com/ErickNjenga>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Thanks ye all, as always, I've learn't sth new. I dug around the jQuery docs and stumbled on the following: var cities = []; $('input:checkbox[name="cities[]"]:checked').each(function(index) { cities.push($(this).val());}); The JS array cities will contain the values of the checkboxes selected, works perfectly with AJAX. On Tue, Sep 6, 2011 at 10:54 AM, Chris Mwirigi <mwirigic@gmail.com> wrote:
var values = $("input[name='cities[]']").serializeArray(); will give you a JS object from the selected checkboxes, you can now convert the object to json and pass to your ajax method.
you can also serialize the entire form and handle the posted data on the server side script
maybe you should post the whole form. might be easier to understand what you exactly want to achieve.
On Tue, Sep 6, 2011 at 10:29 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
Maybe I should have explained my goal; to 'harvest' all form data when the user clicks the submit button, then submit them using jQuery powered AJAX.
If the user checked 2 out of the 3 checkboxes, will jQuery 'remember' the ones the user checked?
On Tue, Sep 6, 2011 at 10:24 AM, Chris Mwirigi <mwirigic@gmail.com>wrote:
+1
On Tue, Sep 6, 2011 at 10:11 AM, Erick Njenga <eriknjenga@gmail.com>wrote:
How about giving them a class attribute and adding something similar to:
$(".class_name").click(function(){
//use $(this) to get the exact checkbox that was clicked
$(this).attr("value"); //This will get the value of the checkbox
});
HTH
Thanks and Regards, Erick Njenga Nyachwaya, M: +254-725-008-790
<http://www.facebook.com/ErickNjenga><http://www.twitter.com/ErickNjenga>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*
participants (3)
-
Chris Mwirigi
-
Erick Njenga
-
Peter Karunyu