0

Hy how can insert in this echo function, return confirm ?

echo "<input type='submit' name='submit' id='submit' class='btn btn-primary' value=Cancella onclick=window.location='delete_article.php?id=".$row['id']."'; /></p>";

i've already have onclick....

6
Contributors
17
Replies
68
Views
3 Years
Discussion Span
Last Post by mattster
0

Try to separate the JavaScript. That will look nice =)

<script>
    function redirect(rowID)
    {
        window.location="delete_article.php?id="+rowID;
    }
</script>

<?php    
    echo "<input type='submit' name='submit' id='submit' class='btn btn-primary' value=Cancella onclick='redirect(\"".$rowId."\");'/>";
?>
1
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Cancella" onclick="confirm('Are you sure?')?window.location='delete_article.php?id=<?=$row['id'];?>':alert('Cancelled');" />
0

i whant to put it in the echo function i've got the problem with the " and '

Edited by bolfescu

0

Close PHP tag and put this button without echo

?>
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Cancella" onclick="confirm('Are you sure?')?window.location='delete_article.php?id=<?=$row['id'];?>':alert('Cancelled');" />
<?php

and then open PHP tag again

0

i' cant put it outside the echo because i have a loop if i will put it outside it will show me always the button....

0

it shows me 10 times the button....
this is the part of the code

 <?php

$qry = mysql_query("SELECT * ,replace(category, ',', ' ') as category FROM articles ORDER BY ID DESC LIMIT 1");  
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<h4>Numero:".$row['id']."</h4>";
echo "<h4>Data:".$row['date']."</h4>";
echo "<h4>Ditta:".$row['category']."</h4>";
echo "<p><input type='submit' name='submit' id='submit' class='btn btn-primary' value='Stampa' onclick=window.location='invoice.php?id=".$row['id']."'; />";
echo "<input type='submit' name='submit' id='submit' class='btn btn-primary' value=Modifica onclick=window.location='edit.php?id=".$row['id']."'; />";
echo "<input type='submit' name='submit' id='submit' class='btn btn-primary' value=Cancella onclick=window.location='delete_article.php?id=".$row['id']."'; /></p>";
}
?>  
0

You can replace line 10 to } ?> line 11 to <h4>Numero:<?=$row['id'];?></h4> without "echo" etc.
Line 17 replace to <?php }

Edited by AndrisP

0
{ ?>
<h4>Numero:<?=$row['id'];?></h4>
<h4>Data:<?=$row['date'];?></h4>
<h4>Ditta:<?=$row['category'];?></h4>
<p><input type="submit" name="submit" id="submit" class="btn btn-primary" value="Stampa" onclick="window.location='invoice.php?id=<?=$row['id'];?>';" />
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Modifica" onclick="window.location='edit.php?id=<?=$row['id'];?>';" />
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Cancella" onclick="confirm('Are you sure?')?window.location='delete_article.php?id=<?=$row['id'];?>':alert('Cancelled');" /></p>
<?php } ?> 

Type of button better replace to button type="button" thear is not form submit, attributes name and id they are unnecessary

Edited by AndrisP

0

Use \", so echo "Quote: \"Hello\" ('mattster' of DaniWeb)"; will return:

Quote: "Hello" ('mattster' of DaniWeb)

In context for you:

echo "<input type='submit' name='submit' id='submit' class='btn btn-primary' value=Cancella onclick=\"window.location='delete_article.php?id=".$row['id']."';\" /></p>";

Still a good idea to neaten your code though.

0

Looking at the code above I can spot two notable errors in post #post They are one to change the window.location upon clicking a button or link you need it to note only be in the onclick event but also have the prefix "JavaScript:". In addition setting the value of a field you need to surround it with double quotes. Note that HTML will only accept double quotes and not single quotes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.