Reputation: 449
i have this checkbox input in my form
<input name='new' type='checkbox' value='0' />
the column new in my database is TINYINT based on the value of the checkbox , i want to display a div with a class if the value is 1 so i implement this code
if(isset($_POST[$URL['new']])
&& isset($_POST[$URL['new']]) == 1)
{
echo '<div class="premiere">Premiere</div>';
}
everything seems working fine , there's no error,warnings and notices.but the div didnot display in the page . what is wrong with the code and how i can fix it? thanks
Upvotes: 0
Views: 2174
Reputation: 449
The prob was , i was trying to access the key from an array in a foreach loops , so i just remove the $_POST from the key and reference like URL['new'] instead. and it works fine.
if(isset($URL['new'])
&& isset($URL['new']) == 1)
{
echo '<div class="new">Premiere</div>';
}
Upvotes: 0
Reputation: 245
You can use this query to display div on checking the checkbox and on unchecking checkbox you can hide the div displayed.
$(document).ready(function(){
$("#new").change(function(e){
var addDiv = $("#new").val();
if($("#new").attr('checked'))
{
$("#form2").append("<div class="premiere">Premiere</div>");
}
else
{
$(".premiere").remove();
}
});
});
HTML Code:
<form method="post" id="form2">
<input id="new" name='new' type='checkbox'/>
</form>
Hoping that this post will be very much useful to you.
Upvotes: 0
Reputation: 481
if ( isset($_POST["new"]) && $_POST["new"] == 1 )
{
echo '<div class="premiere">Premiere</div>';
}
Make sure class "premiere" not hidden through css code.
Upvotes: 0
Reputation: 5522
if ( isset($_POST["new"]) && $_POST["new"] == 1 )
{
echo '<div class="premiere">Premiere</div>';
}
Upvotes: 2
Reputation: 2561
i think, you have apply second condition to check value of "new" variable.
you should write condition like this
if(isset($_POST[$URL['new']]) && $_POST[$URL['new']] == 1){
}
else{
}
Upvotes: 0