Jump to content

Archived

This topic is now archived and is closed to further replies.

SieRobin

Confirm

Recommended Posts

Yeah I'm new to javascript, I'm used to PHP. How in the world do I print a variable into a confirm message? It's starting to really bug me lol.

Share this post


Link to post
Share on other sites
something like this?
[code]
<script language="javascript">
var txt = "variable??";
confirm("try this " + txt + " and see if it works");
</script>
[/code]

Share this post


Link to post
Share on other sites
Yeah that works.. what I'm trying to do is use a $_GET in javascript, is there like an equivlant statement in javascript to do that?

Share this post


Link to post
Share on other sites
the $_GET is a php variable, so you can just use it in the confirm (if the page is php)
[code]
confirm ("<?= addslashes($_GET['variable']) ?>");
[/code]
just make sure your variable doesn't have any line breaks.

Otherwise, you can take a look at this post

http://www.phpfreaks.com/forums/index.php/topic,102096.0.html

Share this post


Link to post
Share on other sites
I did the $_GET variable like that, problem is.. with a confirm the URL doesn't load until you pick "Ok" or "Cancel"

Share this post


Link to post
Share on other sites
[quote author=SieRobin link=topic=102901.msg409135#msg409135 date=1154634225]
problem is.. with a confirm the URL doesn't load until you pick "Ok" or "Cancel"
[/quote]

OK, I'm confused.  What exactly are you trying to do with the javascript confirm function?  Some specifics would help us point towards a solution (if one exists).

Share this post


Link to post
Share on other sites
I'm trying to make it so when a user sells an item, it shows a confirm that says.

"Are you sure you want to sell your $itemname for $howmuchgold Gold?"

How I do this, I don't know. I could make it so it doesn't show the variables.. BUT then they won't know what they're confirming or not.

Share this post


Link to post
Share on other sites
could you post the output HTML you have so far?

Share this post


Link to post
Share on other sites
[code]$sellp=$uinventory3['cost']*.6;
$sell=$_GET['sell'];
$item=$_GET['item'];
$name=$_GET['name'];
$sellid=mysql_query("SELECT * from inventory where IID='$item' AND UID='$userstats3[ID]'");
$sellid2=mysql_fetch_array($sellid);
print "<td>$uinventory3[name]</td>";
print "<td><a href='inventory.php?sell=$sellp&item=$inventory3[IID]&name=$uinventory3[name]' onclick='return sellitem();'>$sellp</a> Gold</td>";
if (isset($sell)&&$item=$sellid2['IID']) {
if ($sellid2['status']==1) {
print "<table class='table'><tr class='headline'><td colspan='4'><center>Inventory</center></td></tr>
<tr class='mainrow'><td><center>You can not sell something that's equipped, please return to your <a href='inventory.php'>inventory</a> to unequip the item you're trying to sell.</center></td></tr></table>";
exit;
} else {
mysql_query("UPDATE users set gold=gold+'$sell' where ID='$userstats3[ID]'");
mysql_query("DELETE from inventory where UID='$userstats3[ID]' AND IID='$item'");
print "<SCRIPT language='JavaScript'>
location.reload('inventory.php')
</script>";
exit;
}[/code]

That's the code for selling the item.

[code]<script language="JavaScript" type="text/javascript">
var message="text";
function sellitem() {
return confirm("Are you sure you want to sell your " + message + " for $sell Gold?");
}
</script>[/code]

This is the javascript with the confirm.

Share this post


Link to post
Share on other sites
you need to pass the variables to the functions

[code]
.......onclick='return sellitem(\"$name_variable\", \"$price_variable\");'.......
[/code]

and your javascript
[code]
function sellitem(nm, prc) {
return confirm("Are you sure you want to sell your " + nm + " for " + prc + " Gold?");
}
[/code]

Share this post


Link to post
Share on other sites
Ok and as for the nm, prc? How does the javascript, know what they are?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.