Print Check Box Selected Data only - php

Hi i am having results and its contains a checkbox as <input type='checkbox' name="ChkS[]" value='<? echo $rs->id?>'>
I have a print out list option in the footer as <input type="button" value="Show Printable List" class="butten" onClick="openPrint()">
Its opening the printable list in new pop up window.
function openPrint() {
window.open("<?= $_SERVER["PHP_SELF"]; ?>?<?=$qstring?>&print=true","","width=1024,height=600,menubar=yes,resizable=yes, scrollbars=yes");
}
I am in need to use the above select checkbox and it should show the selected print list in the pop up ?
I hope it should not be problem any1 to understand it. Any help ?

Javascript Modification:
var s = "";
function changeval(value) {
s = value;
}
function openPrint() {
alert(s);
window.open("<?= $_SERVER["PHP_SELF"]; ?>?<?=$qstring?>&print=true","","width=1024,height=600,menubar=yes,resizable=yes, scrollbars=yes");
}
HTML Modification:
<input type='checkbox' name="ChkS[]" value='<? echo $rs->id?>' onchange="changeval(this.value)" />
What I have done?
Created an Global Variable s.
Attached or Bind onchange event on checkbox and set the value of Variable s according.
Now, You have variable s with value, you just have to use it in any function.

Currently you have defined button onclick event , instead of this set onclick event on
checkbox.
<input type='checkbox' name="ChkS[]" value='<? echo $rs->id?>' onClick="openPrint();">
Hope this will help you to solve your problem.

Related

JQuery Change Checkboxes in Dynamic Table

I am creating a table based on rows returned from a MySQL query using PHP:
while($row = mysqli_fetch_array($query_results)){
echo "<tr>";
echo "<td>$row[Title]</td>";
echo "<td>$row[Name]</td>";
echo "<td><input class='row-$i' id='one-$i' type='checkbox' ($row[check_one]==1 ? 'checked' : '')/></td>";
echo "<td><input class='row-$i' id='two-$i' type='checkbox' ($row[check_two]==1 ? 'checked' : '')/></td>";
echo "</tr>";
$i++
}
What I want to have happen is if the first checkbox is checked and you check the second one, the first checkbox becomes unchecked. I was originally going to use radio buttons to accomplish this, but the user also needs to be able to freely check or uncheck the first check box (ie both can be unchecked at one time), so radio buttons won't work. So what I need to do is detect change for two-$i elements, but am not sure how to do so for a dynamic element. Under normal circumstances the JQuery would be:
$('#two').change(function(){...});
So how can I modify this to work on the dynamic ids?
function change(val)
{
if(val=='one-1')
document.getElementById('two-2').checked=false
else
document.getElementById('one-1').checked=false
}
First<input type="checkbox" id="one-1" value="one-1" onClick="change(this.value);"/><br>
Second<input type="checkbox" id="two-2" value="two-2" onClick="change(this.value);"/>
This will help you.
Happy Coding.
$(document).ready(function(){
$("#table > input[type='checkbox']").on("click",function(){
$('#table > input:checkbox').not(this).removeAttr('checked');
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="table">
First<input type="checkbox" id="one-1" value="one-1" /><br>
Second<input type="checkbox" id="two-2" value="two-2" /><br>
Third<input type="checkbox" id="two-2" value="two-2" />
</div>

Unable to find if radio button is checked

I have made a few radio buttons in my php code
echo "<input type='radio' name='rad' value='a'>";
echo "<input type='radio' name='rad' value='b'>";
and my html code is
<form method="post" action="fetch_page_4.php">
<input type="submit" name="submit1" value="Positive" id="btn1"/>
<input type="submit" name="submit2" value="Negative" id="btn2"/></form>
Whenever i click the Positive or Negative button it should go into the respective part in PHP...which it does. But the problem is that i need to find out which of my radio buttons is checked and take the action accordingly.
But i am unable to do so. My code for it is
if(isset($_POST['submit1']))
{
$main_key=0;
if(isset($_POST['rad']) && ($_POST['rad'])=='a')
{
$sub_arr=explode(" ",$array_subject[0]);
$count_sub=count($sub_arr);
$body_arr=explode(" ",$array_message[0]);
$count_msg=count($body_arr);
$main_key=1;
}
}
If i echo the value of "main_key" after this...it is coming out to be 0, thus indicating that it is not going inside the loop even when the radio button is checked and has the required value.
Can somebody please tell me why is this happening?

Issues with javascript validation of radio buttons on php form

This is the code for the php file containing the form with radio buttons:
<?php
while($r7 = mysql_fetch_array($rt3)){
$name=$r7["name"];
$s=$r7["question"];
echo "
<div>$s</div>
<form name='Tester' method='post' onSubmit='return RegValidate(this);' action='quest.php' >
<input type='radio' name='w1' value='1'>1<br>
<input type='radio' name='w1' value='2'>2<br>
<input type='radio' name='w1' value='3'>3<br>
";
}
echo" <input name='Submit' value='Tester' type='submit' />
</form>";
?>
The $name and $q are derived from the database using a mysql query. This works fine.
I have used the following javascript code so far:
function RegValidate(Tester)
{
if($('#w1').not(':checked'))
{
alert('Radio not checked');
return false;
}
}
But with this code, I continue to get the error message, and I am not able to move on even though I have selected a radio button.
The while loop produces several sets of radio buttons, as $q, gets the question from the database and posts it on the page along with 3 radio buttons. Each question $q, has the 3 radio buttons in the above, hence the reason for the $name.
How do I validate this form with javascript. NB. The form will only contain radio buttons.
function RegValidate(Tester) {
if ($(":radio[name=w1]:checked").toArray().length == 0) {
alert('nothing selected');
return false;
}
}​
FIDDLE
you have an error, your input doesn't have ID or CLASS, so add to all of the input radio class='w1' and try the next code:
if ($(".w1 option:selected").length<1)
alert ('nothing selected');
also take a look to this post: Check if option is selected with jQuery, if not select a default
do these things:
<input type='radio' class='w1' name='w1' value='1'>1<br>
<input type='radio' class='w1' name='w1' value='2'>2<br>
<input type='radio' class='w1' name='w1' value='3'>3<br>
And in js:
Latest edit:
if ( $(':radio[class=w1]').attr('checked') != 'checked' ) {
alert('Radio not checked');
}

enable the array of textboxes php javascript

I got the array of disabled text boxes from the database. When I click on edit button it should enable all the text boxes which are in array. But i could only enable the first text box. Here is the code.
code for edit button:
<input type="button" value="Edit" onclick="enable();" />
function enable()
function enable(){
document.getElementById("instance_name").disable = false;
document.getElementById("host_name").disable = false;
}
array:
$result=mysql_query("SELECT user_instance.instance_name, user_instance.host_name FROM
dba_account, user_instance WHERE dba_account.account_id = user_instance.account_id AND
dba_account.account_id = '$accid'");
while($note = mysql_fetch_array($result))
{
<inut type='text' name='instance_name' id='instance_name' disabled='disabled'
value='$note[instance_name]' size='25' />
<input type='text' name='host_name' id='host_name' disabled='disabled'
value='$note[host_name]' size='25' />
}
I am getting all the disabled textboxes, but i can not anable them all. Appreciate your help.
You're giving the same ID to multiple elements. Each ID can only be unique to one element, so once javascript finds the first ID, it stops. I'd give it a class="instance_name" instead and then get the elements by class instead. You could do something like this:
function enable(){
Array.prototype.forEach.call( document.getElementsByClassName('instance_name'),
function(element){
element.removeAttribute('disabled');
});
}

Inserting a id value into a <a> tag?

i wanted to input a id value into a tag, where the value is hidden but i want to pass that value to another page . I have the code for input type however i have no idea how to do it on a tag.
codes for input type:
<input type='hidden' name='id' value='$id'/>
<input type='submit' value='More details' />
how to archieve the same effect on tag?
There's no way to pass information in a link (an <a> tag) besides putting it in the URL.
You can put an onclick event on the specific tag that changes the hidden input fields value. e.g.
Test
function setHidVal(idVal)
{
$(function(){ $('#myHiddenField').val(idVal); }); //You don't have to use jquery
}
So once posted, you can request the hidden field name to get value.
what is the problem? any value of a form`s input, even in a hidden input you find in
$_POST[id]
You can append in a tag like this.
Method 1:
<a href="your-page.ext?id=<? echo $id; ?>">
Method 2:
<form name="hidden_form">
<input type='hidden' name='id' value='$id'/>
</form>
<a href="your-page.ext" onclick="javascript:return submit_frm(this)" > some thing goes here</a>
<script>
function submit_frm(aelem) {
document.hidden_form.action = aelem.href;
document.hidden_form.submit();
return false;
}
</script>

Categories