php - how do i passing checkbox to another page using javascript? -


how pass checkbox value page using javascript have code below can't pass checkbox values retrieving fields mysql database table records?

javascript

<script type="text/javascript"> function getvalue(checkbox) { var sstr2 = "search.php?color="+ encodeuri(document.getelementbyid('color').checked); window.location.href = sstr2; return false; } </script> 

form

<form action="" name="color1" id="color1" method="post">  <?php $querycolor=mysql_query("select count(id) cnt, color, id  products group color order id");  while($rowcolor=mysql_fetch_array($querycolor)) { $colors=$rowcolor['cnt']."<br />"; $colorid=$rowcolor['id']; ?> <input name="color" type="checkbox" id="color" value="<?php echo $rowcolor['color'];?>" onclick="getvalue(this.value)" >   <font class="font1"> <?php echo $rowcolor['color'];?>&nbsp;<?php echo $colors ?></font><br />  <?php }?></form> 

<script type="text/javascript"> function getvalue(checkbox) {  var sstr2 = "search.php?color="+ encodeuri(checkbox); window.location.href = sstr2; return false; } </script> 

you passing value of checkbox. not passing checkbox...

see, code

onclick="getvalue(this.value)"  

which says, checkbox's value if clicked... remember, solution not check if checkbox selected or unselected, checks if clicked, value gets passed..

good way stuff check boxes id/name , see how many of them selected, , pass of them url..

var allvals = [];      $('#color:checked').each(function() {        allvals.push($(this).val());      });      $('#t').val(allvals) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -