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....

Recommended Answers

All 17 Replies

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."\");'/>";
?>
<a class="field_delete" onClick="return confirm('Are you sure you want to delete')"  href="#">Delete</a> 
<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');" />

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

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

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....

It isn't problem

<?php for($i=0; $i<10; $i++){ ?>
<input type="button" />
<?php } ?>

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>";
}
?>  

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

still dont get it...

{ ?>
<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

it is not correct elements with the same ID in the one document

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.

still doesnt work....

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.

if this <?=$row['id'];?> don't work
then replace to <?php echo $row['id']; ?>

^^ needs a space beetween the = and $, so <?= $row['id']; ?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.