works only in bootstrap
<div class="button-group"> <button type="button" class="btn btn-default btn-sm dropdown-toggle form-control" data-toggle="dropdown"> Select Country <span class="caret"></span> </button> <ul class="dropdown-menu form-control" style="height:160px; overflow-x: hidden;"> <? $sql="SELECT * from country"; $result=mysqli_query($con,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_assoc($result)) { ?> <li class="form-control"> <input type="checkbox" value="<? echo $row['country_name'];?>" name ="chk[]"/> <? echo $row['country_name'];?></li> <?} }?> </ul> </div>
without bootstrap
use script
<script>
var options = [];
$( '.dropdown-menu a' ).on( 'click', function( event ) {
var $target = $( event.currentTarget ),
val = $target.attr( 'data-value' ),
$inp = $target.find( 'input' ),
idx;
if ( ( idx = options.indexOf( val ) ) > -1 ) {
options.splice( idx, 1 );
setTimeout( function() { $inp.prop( 'checked', false ) }, 0);
} else {
options.push( val );
setTimeout( function() { $inp.prop( 'checked', true ) }, 0);
}
$( event.target ).blur();
console.log( options );
return false;
});
</script>
<?
$chk =$_POST['chk'];
foreach( $chk as $key=>$value )
{
$sql= "INSERT INTO company_login (country,company_name,email,password,signup_time,signup_date) VALUES ('$value','$cname','$cemail','$cpass','$ctime','$cdate')";
if(mysqli_query($con,$sql))
{
header("Location:a_company.php");
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
}
<div class="button-group"> <button type="button" class="btn btn-default btn-sm dropdown-toggle form-control" data-toggle="dropdown"> Select Country <span class="caret"></span> </button> <ul class="dropdown-menu form-control" style="height:160px; overflow-x: hidden;"> <? $sql="SELECT * from country"; $result=mysqli_query($con,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_assoc($result)) { ?> <li class="form-control"> <input type="checkbox" value="<? echo $row['country_name'];?>" name ="chk[]"/> <? echo $row['country_name'];?></li> <?} }?> </ul> </div>
without bootstrap
use script
<script>
var options = [];
$( '.dropdown-menu a' ).on( 'click', function( event ) {
var $target = $( event.currentTarget ),
val = $target.attr( 'data-value' ),
$inp = $target.find( 'input' ),
idx;
if ( ( idx = options.indexOf( val ) ) > -1 ) {
options.splice( idx, 1 );
setTimeout( function() { $inp.prop( 'checked', false ) }, 0);
} else {
options.push( val );
setTimeout( function() { $inp.prop( 'checked', true ) }, 0);
}
$( event.target ).blur();
console.log( options );
return false;
});
</script>
<?
$chk =$_POST['chk'];
foreach( $chk as $key=>$value )
{
$sql= "INSERT INTO company_login (country,company_name,email,password,signup_time,signup_date) VALUES ('$value','$cname','$cemail','$cpass','$ctime','$cdate')";
if(mysqli_query($con,$sql))
{
header("Location:a_company.php");
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
}
Comments
Post a Comment