how to concatenate multiple check box values in same fields
Pls rply me fast........... ........
Pls rply me fast........... ........
<INPUT TYPE="Checkbox" CHECKED>
if(certain_condition_fulfilled()==true)
{
$sel="SELECTED";
}
else $set="";
?>
<INPUT TYPE="Checkbox" <?php echo $set;?>>
<html>
<head>
<title>Serializing Checkbox</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(
function()
{
$("#test").click(
function() {
serializeCheckbox();
}
);
}
);
function serializeCheckbox()
{
var string = '&string=';
var inputs = document.getElementsByTagName('input');
for( var x = 0; x < inputs.length; x++ )
{
if(inputs[x].type == "checkbox" && inputs[x].name == 'field')
{
if(inputs[x].checked == true)
{
string += inputs[x].value + ',';
}
}
}
if (/,$/.test(string)) {
string=string.replace(/,$/,"")
}
alert(string);
}
</script>
</head>
<body>
<form>
<input type="button" id="test" value="Click me" />
<br />
<input name="field" type="checkbox" value="blue" />Blue<br />
<input name="field" type="checkbox" value="red" />Red<br />
<input name="field" type="checkbox" value="green" />Green<br />
</form>
</body>
</html>
$concated_str = '';
if(isset($_POST['checkboxvalues'])){
$concated_str = implode(',',$_POST['checkboxvalues']);
}
//store $concated_str in the database
Comment