dynamically created button hide in php - php

I have created button using this:
$i=1;
while($row=mysql_fetch_array($e))
{
echo '<td><img src="'.$path.$row['photo'].'" border="0" width=100 height=50/></td>';
echo $row['fname'];
echo "<input type=\"button\" value=\"send request\" name=\"$i\" onclick=\"sendreq('".$row['uname']."')\"/>";
//echo $i;
echo "<br/>";
$i=$i+1;
}
and passing the username onclick of the button through sendreq() function.This is javascript function. I just want to hide this button when sendreq() job is done.

You could use the javascript to assign is the display:none; CSS attribute, though I am uncertain whether it would have to be applied to an encapsulating div or whether it would work directly on the image itself.

$i=1;
while($row=mysql_fetch_array($e))
{
echo '<td><img src="'.$path.$row['photo'].'" border="0" width=100 height=50/>
</td>';
echo $row['fname'];
echo "<input id='btnSubmit' type=\"button\" value=\"send request\" name=\"$i\"
onclick=\"sendreq('".$row['uname']."');
document.GetElementById('btnSubmit').hide(); \"/>";
//echo $i;
echo "<br/>";
$i=$i+1;
}
after the method is executed, the element will hide.

you can add this line at the end of the function.
<script>
jQuery("#btnSubmit").hide();
</script>
hope this helps...

edit your input button tag like this
assign a id to button (such as i used remove as id here) and add this code on last of the function sendreg
document.getElementById("remove").style.display='none';
or use jquery functions like
$("#remove").hide();
or $("#remove").fadeOut(3000);

Related

Unexpected exception caught of input in PHP tag which has HTML

I Have a delete button where I want to pass a parameter to PHP function. But it gives me Uncaught SyntaxError: Unexpected end of input error in chrome console. According to my knowledge, there isn't any syntax error. below you can find my code.
<tbody>
<?php foreach($orderData as $order){
$id = $order["order_id"];
echo "<tr>";
echo "<td>".$order["order_id"]."</td>";
echo "<td>".$order["customer_name"]."</td>";
echo "<td>".$order["addedperson_id"]."</td>";
echo "<td>".$order["total"]."</td>";
echo "<td>".$order["added_date"]."</td>";
echo "<td align='center'><button class='btn btn-danger' name='close' id='close' onclick='".base_url()."index.php/order/suspend/".$id."'>delete</button></td>";
echo "</tr>";
} ?>
</tbody>
This is the place where I get the error in the google console
Pass your Javascript code inside the Page where you will output the button, my personal suggestion is to use Jquery to manage the click event so from your php script you can echo the html code without any error or problem. Just assign an id to the button then write the JS code referred to the button id.
Example:
<tbody>
<?php
foreach($orderData as $order){
$id = $order["order_id"];
echo "<tr>";
echo "<td>".$order["order_id"]."</td>";
echo "<td>".$order["customer_name"]."</td>";
echo "<td>".$order["addedperson_id"]."</td>";
echo "<td>".$order["total"]."</td>";
echo "<td>".$order["added_date"]."</td>";
echo "<td align='center'><button class='btn btn-danger' name='close' id='close'>delete</button></td>";
echo "</tr>";
}
?>
</tbody>
$('#close').on('click', function(e){
e.preventDefault();
// your code
});

Link for same page

Longtime reader of stackoverflow but second question.
This is what i am doing
echo "<td><a href = 'http://localhost/map/index.php'
value='$id' >Delete</a></td>";
This is what we do when we use submit button
<?php
echo "<body style='background-color:gray'>";
if (isset ($_POST['submit'])){
include("connection.php");
echo " <table id='t01' border='20px solid black' width='100%' >";
echo "<tr>";
echo "<th> DETAILS ABOUT DELETION</th>";
echo "<td>DELETED SUCCESSFULLY </td></tr>";
$id = $_POST["submit"];
$select1="DELETE FROM app where id='$id'";
$result = $conn->query($select1);
if ($conn->query($result)==true){
echo "<td>DELETED SUCCESSFULLY </td></tr>";
}
echo "</table>";
//echo "DELETED SUCCESSFULLY";
}
?>
I just want to do something like that * without using input type=submit* ..... But dont know how to do
Any advice will be appreciated ... Thanks in advance
firstly pass the id in the url like so:
echo "<td><a href = 'http://localhost/map/index.php?id=$id'>Delete</a><td>";
then check it with:
if (isset ($_GET['id'])){
...
you basically swapping POST for GET

Retrieve data in html table cell - PHP

I'm loading data from an xml file into a html table then adding a check box column at the end with the view of saving the data from each row where the check box is checked, for now I just want to display the rows with the check box checked.
In my first page I have the code below which successfully loads the xml data in to the html table and displays it as I wanted, forgive my code, it is a bit messy as I'm new to PHP.
<?php
<form method="POST" action="saved.php">
echo "<input type='submit' name='save' value='Save Checked Rows' />";
$all = simplexml_load_file('list.xml');
echo "<div style='height:200px; overflow-y: scroll;'>";
echo "<table border=\"1\">";
echo "<th>Title</th><th>Description</th><th>Link</th><th>Save</th>\n";
echo "<tr>";
$c=0;
foreach ($all as $current) {
$title=$current->title;
$description=$current->description;
$link=$current->link;
echo "<td>{$title}</td><td>{$description}</td><td><a href=$link>$link</a></td><td><input type='checkbox' name='save[]' value='$c' /></td>";
$c++;
echo "</tr>\n"; }
echo "</table>";
echo "</div>";
echo "</form>"
?>
On my second page I have the code below which displays the value of every check box that is checked when I submit the first page
<?php
Session_start();
?>
<?php
foreach($_POST['save'] as $key){
echo $key;}
}
?>
I need to get the data from the other table cells on the checked rows, the only idea that worked so far was putting an input in to the cell but I don't want that because the cells have to be uneditable. Thanks for the help !
For that there is an atribute in html which you can use i,e read only

Toggle rows of a table inside while loop

I have a table with several buttons with "SHOW" text. Everytime I click one of those buttons I'd like that rows with class ".infotr" appears and when I click again the same button those rows disappear. (I mean the ".infotr" rows of the same table of the clicked button.)
<?php
$sql="SELECT * FROM mytable WHERE ID='$id'";
$res=mysqli_query($db,$sql);
while($row = mysqli_fetch_array($res))
{
echo "<table id='tablemodificamobile'>";
echo "<tr id='firsttr'>";
echo "<td id='amid' class='modificatd'>".$myid."</td>";
echo "<td id='amtitle' class='modificatd'>".$row['Title']."</td>";
echo "<td id='amshow' class='modificatd'><input type='button' id='mostramodbtn' value='SHOW'></input></td>";
echo "</tr>";
echo "<tr class='infotr'><td class='addinfo'>New Price: ".$row['NewPrice']."</td></tr>";
echo "<tr class='infotr'><td class='addinfo'>Old Price: ".$row['OldPrice']."</td></tr>";
echo "<tr class='infotr'><td class='addinfo'><input type='button' value='SAVE' id='modit'></input></td></tr>";
echo "</table>";
}
?>
This is what I tried but it doesn't work:
$('#mostramodbtn').click(function() {
$(this).parents("tr").nextAll().show();
});
Use this:
$(document).on('click','#mostramodbtn',function() {
$(this).parents("tr").nextAll().toggle("slow");
});
You are creating the element dynamically so you need to bind the even on document with .on function.
Learn more about .on() function in jQuery here.

confirm dialog box in php

I have this echo statement:
echo "<td align=center style=border:0>"."<a href='?delete=$row[id]'>Delete</a>"."</td>";
how am I able to make that when I press the 'Delete' a yes no dialog box will appear?
I've read somewhere that it can add some thing like this somewhere in the statement:
onClick="javascript:return confirm(\'Are you sure you want to delete this record?\')"
Any help would be appreciated.
thanks in advance.
Try this:
echo "<td align=center style=border:0><a onclick='return confirm(\"Are you sure you want to delete this record?\")' href='?delete=$row[id]'>Delete</a></td>";
I got rid of the unnecessary "." in your original code.
Just Use this
echo "<td align=center style=border:0><a onclick='return confirm(\"Are you sure you want to delete this record?\")' href='?delete=$row[id]'>Delete</a></td>";
Instead of
echo "<td align=center style=border:0>"."<a href='?delete=$row[id]'>Delete</a>"."</td>";

Categories