0

i want to set value to checkbox,how do it? this is my code: from this code only i could get upto link,image,name value,why? i want to get link,image,name,description,categ value.how do it?

$results=$watch.",".$thumbnail.",".$name.",".$description.",".$val;
<input type="checkbox" name="checkbox[]" id="checkbox[]" class="addbtn"  value=<?php echo  $results;?>

this is my javascript function to get the checkbox value.

function chkbox() {
    $('[name^=checkbox]:checked').each(function() {

        var ckballvalue = ($(this).val());

        var latlngStrs = ckballvalue.split(",", 5);
        var link = latlngStrs[0];
        var thumbnail = latlngStrs[1];
        var name = latlngStrs[2];
        var description = latlngStrs[3];
        var categ = latlngStrs[4];

        alert(link + thumbnail + name + description + categ);
    }
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
SANSCLAW
  • 23
  • 1
  • 4
  • 15
  • 1
    Possible duplicate: [http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery-or-javascript](http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery-or-javascript) – cegfault Mar 29 '12 at 22:09
  • Don't you think checkbox hold just hold the value as checked and unchecked? What's $result? – Hamza Waqas Mar 29 '12 at 22:12
  • just i set the $results to checkbox value.results=$watch.",".$thumbnail.",".$name.",".$description.",".$val; – SANSCLAW Mar 29 '12 at 22:13
  • i could not get the $watch.",".$thumbnail.",".$name.",".$description.",".$val; values in javascript. so how to get? – SANSCLAW Mar 29 '12 at 22:15
  • Have you tried wrapping the value in quotes? (Is there a space in your name?) – Pete Mar 29 '12 at 23:07
  • `$('[name^=checkbox]:checked')` is pretty slow as it needs to iterate over every single element. use `$('input[name^=checkbox]:checked')` instead. Or even better, give all elements you want to select a class and then use `$('input.whateverclass:checked')`, e.g. `$('input.addbtn:checkbox:checked')` – ThiefMaster Jun 13 '12 at 12:40

1 Answers1

0

I've tried to revise your code.

When doing it like this it works:

$("input.addbtn").click(function() {

    var val = $(this).val();

    var arr = val.split(',', 5);

    var link = arr[0];
    var thumb = arr[1];
    var name = arr[2];
    var desc = arr[3];
    var cat = arr[4];

    alert(link + "|" + thumb + "|" + name + "|" + desc + "|" + cat);
});

I hope this helps

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
mike b
  • 56
  • 2