SieRobin Posted August 3, 2006 Share Posted August 3, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16482-confirm/ Share on other sites More sharing options...
nogray Posted August 3, 2006 Share Posted August 3, 2006 something like this?[code]<script language="javascript"> var txt = "variable??"; confirm("try this " + txt + " and see if it works");</script>[/code] Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68784 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 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? Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68789 Share on other sites More sharing options...
nogray Posted August 3, 2006 Share Posted August 3, 2006 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 posthttp://www.phpfreaks.com/forums/index.php/topic,102096.0.html Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68794 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 I did the $_GET variable like that, problem is.. with a confirm the URL doesn't load until you pick "Ok" or "Cancel" Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68795 Share on other sites More sharing options...
AndyB Posted August 3, 2006 Share Posted August 3, 2006 [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). Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68802 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68809 Share on other sites More sharing options...
nogray Posted August 3, 2006 Share Posted August 3, 2006 could you post the output HTML you have so far? Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68811 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68821 Share on other sites More sharing options...
nogray Posted August 3, 2006 Share Posted August 3, 2006 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] Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68822 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 Ok and as for the nm, prc? How does the javascript, know what they are? Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68827 Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 Nevermind I got it, thank you very much :] Link to comment https://forums.phpfreaks.com/topic/16482-confirm/#findComment-68833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.