Jump to content


Photo

Confirm


  • Please log in to reply
11 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 06:50 PM

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.

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 August 2006 - 07:31 PM

something like this?
<script language="javascript">
	var txt = "variable??";
	confirm("try this " + txt + " and see if it works");
</script>

NoGray.com


#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 07:36 PM

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?

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 August 2006 - 07:39 PM

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

Otherwise, you can take a look at this post

http://www.phpfreaks...c,102096.0.html


NoGray.com


#5 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 07:43 PM

I did the $_GET variable like that, problem is.. with a confirm the URL doesn't load until you pick "Ok" or "Cancel"

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 August 2006 - 07:59 PM

problem is.. with a confirm the URL doesn't load until you pick "Ok" or "Cancel"


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).
Legend has it that reading the manual never killed anyone.
My site

#7 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 08:07 PM

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.

#8 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 August 2006 - 08:10 PM

could you post the output HTML you have so far?

NoGray.com


#9 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 08:26 PM

$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;
	}

That's the code for selling the item.

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

This is the javascript with the confirm.

#10 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 August 2006 - 08:31 PM

you need to pass the variables to the functions

.......onclick='return sellitem(\"$name_variable\", \"$price_variable\");'.......

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

NoGray.com


#11 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 08:39 PM

Ok and as for the nm, prc? How does the javascript, know what they are?

#12 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 08:45 PM

Nevermind I got it, thank you very much :]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users