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. Quote Link to comment 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] Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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" Quote Link to comment 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). Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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? Quote Link to comment 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 :] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.