//toggle check all
$("#bill-all").click(function(){
if( $(this).is(":checked") ){
$('.bill_fillter').prop('checked', true);
} else {
$('.bill_fillter').prop('checked', false);
}
});
Html:Code
If i check here.
<input type="checkbox" name="all" id="bill-all" />
Check All is not working, nothing gonna checked if i checked
<input type="checkbox" name="bill_<?php echo($i);?>" report_date="<?php echo $a1[1]; ?>" value="<?php echo($unit_id);?>" class="bill_fillter" id="bill-all"/>
$("#bill-all").click(function(){
if( $(this).is(":checked") )
$(".bill_filter").prop('checked', true);
else
$(".bill_filter").prop('checked', false);
});
Remove id form -
<input type="checkbox" name="bill_<?php echo($i);?>" report_date="<?php echo $a1[1]; ?>" value="<?php echo($unit_id);?>" class="bill_fillter" id="bill-all"/>
Try with -
<input type="checkbox" name="bill_<?php echo($i);?>" report_date="<?php echo $a1[1]; ?>" value="<?php echo($unit_id);?>" class="bill_fillter"/>
Sample -
<input type="checkbox" name="bill" class="bill_fillter" />
<input type="checkbox" name="bill" class="bill_fillter" />
<input type="checkbox" name="bill" class="bill_fillter" />
<hr />
<input type="checkbox" name="all" id="bill-all" />
Script -
$(document).ready(function() {
$("#bill-all").click(function(){
if( $(this).is(":checked") ){
$('.bill_fillter').prop('checked', true);
} else {
$('.bill_fillter').prop('checked', false);
}
});
I suspect your not binding the click event on document ready.
Given the HTML as an example
<input type="checkbox" id="bill-all" /><br /><br />
<input type="checkbox" class="bill_filter" /><br />
<input type="checkbox" class="bill_filter" /><br />
<input type="checkbox" class="bill_filter" />
The javascript code needs to be executed when the DOM (document) is ready, e.g. all HTML elements are available.
$(function() {
$('#bill-all').click(function() {
$('.bill_filter').prop("checked", $(this).is(':checked'));
});
});
Related
I have this wizard that needs to display the previous posted value
index.html
<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
in the posted.php i have a similar form only this time i know the value from $_POST
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
I am having a hard time trying to come up with a solution that shows what checkbox was checked.I have seen several solutions like https://stackoverflow.com/a/11424091/1411148 but i wondering if there more solution probably in html5 or jquery.
How can i show what checkbox was checked?.The probem i am having is that <input type="checkbox" name="jquery" checked /> checked checks the checkbox and no post data can be added to show what the user checked.
This would be a way to go:
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" <?php if (isset($_POST['php'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="jquery" <?php if (isset($_POST['jquery'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="python" <?php if (isset($_POST['python'])) echo 'checked="checked"'; ?> />
<input type="submit" value="Submit" />
</form>
I am new to php and mysql. i've used radio buttons to save the type of my account records i can insert the data successfully but when i try to get that data (whether type S is selected or type T is selected) from sql to update it further i cant do that. i dont know how to get the data of radio buttons from my sql.. please help
<form method="post" action="users-edit-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email; ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Student<br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Teacher<br />
<input type="submit" value="Edit" />
</form>
this is how i get the value from database.. im sure iam doing wrong, please help me solve this..
You have to check which type you got from the database and according to that add this attribute to the input element: checked="checked". So the whole selected tag would look like this:
<input name="type" type="radio" checked="checked" value="the one PHP returned" />
And the other input tag would also be there, but without the checked attribute.
You just need to do the PHP check on what element to put the attribute.
The whole part:
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo 'checked="checked"'; ?>" /> Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo 'checked="checked"'; ?>" /> Teacher<br />
The value of your radio-buttons is fixed and does not depend on the value in the database, only whether it is checked or not.
It should be something like:
<input type="radio" name="type" value="S" <?php echo ($type == 'S') ? 'checked' : ''; ?> /> Student<br />
<input type="radio" name="type" value="T" <?php echo ($type == 'T') ? 'checked' : ''; ?> /> Teacher<br />
This is the checkbox
<input id="c1" type="checkbox" name="hour[]" class="create-daily" value="1" /><br />
<input id="c2" type="checkbox" name="hour[]" class="create-daily" value="2" /><br />
<input id="c3" type="checkbox" name="hour[]" class="create-daily" value="3" /><br />
I have a dialog
<div id="form_input" title="Konfirmasi">
<?php $data['hour'] = $this->input->post('hour');?>
<table>
<?php echo form_open('booking/ok'); ?>
<input type="hidden" value='' id="id" name="id">
<input type="hidden" value="<?php echo $sdate?>" id="sdate" name="sdate" />
<?php echo "Anda memesan room : <br/>Tanggal :<b> ".$sdate."</b><br>";?>
Jam : <b><span class="jambooking"></span></b>
<tr>
<td>
<div class="element">
<label class="Norm">Jam:</label>
<input type="text" name="jam" class="jambooking" id="jam" minlength="2" value="" />
</div>
<label class="Norm">User:</label>
<input type="text" name="user" class="required text" minlength="2" />
</div>
I have javascript
$(".create-daily").live("click",function(){
if ($(this).attr("checked")){
//var date = $(this).attr("date");
//$('#date').val(date);
$( "#form_input" ).dialog( "open" );
$(".jambooking").html( $(":checked").val());
}
});
I use a span and input with a class set to jambooking. When I checked a check box and show a dialog, the span shows a value.
When I set to the input class jambooking the value does not show.
How would I load a value to the text field?
Try:
$(".create-daily").live("click",function(){
if ($(this).is(":checked")){
var checkedVal = $(this).val();
//$('#date').val(date);
$( "#form_input" ).dialog( "open" );
$("span.jambooking").html(checkedVal); //for span
$("input.jambooking").val(checkedVal); //for textbox
}
});
Since you are using an input, you should use .val() instead of .html()
$(".jambooking").val( $(":checked").val());
$().html is for div. $().text is for <p>. You have to use different one for input field. Use $().val();
Change this one.
From
$(".jambooking").html( $(":checked").val());
To
$("input.jambooking:text").val( $(":checked").val());
check this out
$(".jambooking").val( $(":checked").val());
or check this link Jquery Text Editor
Hope it works.
this is my form
<form name="thumbnail" action="<?php echo $_SERVER["PHP_SELF"];?>?complete=true" method="post">
<input type="hidden" name="x1" value="" id="x1" />
<input type="hidden" name="y1" value="" id="y1" />
<input type="hidden" name="x2" value="" id="x2" />
<input type="hidden" name="y2" value="" id="y2" />
<input type="hidden" name="w" value="" id="w" />
<input type="hidden" name="h" value="" id="h" />
<input style="margin-top:7px;" type="submit" name="upload_thumbnail" value="Save Thumbnail" id="save_thumb" />
</form>
and on the page i have this
<?php
print_r($_GET);
if($_GET["complete"] == "true"){ ?>
<script type="text/javascript">
parent.jQuery.fancybox.close();
</script>
<?php } ?>
but the get is always nothing..why is that when i add ?complete=true to the string
i tried GET POST but nothing....any ideas on how to do this
It works for me...
Array
(
[complete] => true
)
<script type="text/javascript">
parent.jQuery.fancybox.close();
</script>
So you have a problem somewhere else.
Also, if you are going to use <?php echo $_SERVER["PHP_SELF"];?> for your form, change it to <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> for security.
Otherwise, I may request index.php/"%20onsubmit="alert('xss');return%20false"%20bla=" which leaves your HTML looking like....
<form name="thumbnail" action="/stuff/euler.php/" onsubmit="alert('xss');return false" bla="?complete=true" method="post">
Maybe try === instead of ==
I would guess the string "true" gets evaluated as true (boolean)
I have this span that is in a loop and produce multiple results.
what I want is the attribute recordID value when its checked
<span id="row" index="<?php print $i; ?>" recordID="<?php print $row->ID; ?>" Color="<?php print $row->Color; ?>">
<input type="checkbox" style="left:10;" />
</span>
I am using this in my js file to check if the checkbox was clicked
var test = $('input:checkbox:checked').val();
alert(test);
And all I get is on
how can I get attribute value
Thanks
This will get you the attribute value
$('#row').attr('recordID');
If you wanted to get the value when the checkbox gets checked, here is an example
js file
$(document).ready(function(){
$('input:checkbox').change(function(){
if($(this).attr('checked')){
alert($(this).parent().attr('recordID'));
}
});
});
To see how many rows have been checked:
JavaScript
$(document).ready(function(){
$('#check').click(function(event){
event.preventDefault();
alert($('input:checkbox:checked').size());
});
});
HTML
<span id="row1" recordID="1">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span>
<span id="row2" recordID="2">
<input type="checkbox" style="left:10;" />
</span>
<span id="row3" recordID="3">
<input type="checkbox" style="left:10;" />
</span>
<span id="row4" recordID="4">
<input type="checkbox" style="left:10;" />
</span>
<button id='check'>Check Num Rows</button>
To check within an individual span
$(document).ready(function(){
$('#check').click(function(event){
event.preventDefault();
alert($('#row1 input:checkbox:checked').size());
});
});
Here is the complete sample code i am using to make the example you need
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$('input:checkbox').change(function(){
alert($(this).parent().find(':checkbox:checked').size());
});
});
</script>
</head>
<body>
<span id="row1" recordID="1">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row2" recordID="2">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row3" recordID="3">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row4" recordID="4">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span>
</body>
</html>