Page 1 of 1
Javascript Box
Posted: Fri Dec 20, 2013 5:36 am
by Epiales
I have gotten a custom popup window to work with, but I cannot get the option of closing the window. I think I've tried most things. This is my code:
Code: Select all
<script type="text/javascript">
function togglePopup(box){
var popupBox = document.getElementById(box);
if(popupBox.style.display == "block"){
popupBox.style.display = "none";
} else {
popupBox.style.display = "block";
}
}
</script>
<div class="popupBox" id="popbox1">
</script> <div class="boxbody">
<div class="boxheader">
Where I put the header of the box
</div>
Then here is the link that they click on to open the box:
Code: Select all
<li><a target="_parent" onmousedown="togglePopup('popbox1')">Store</a>
I've tried putting a button there with a mousedown, an onlick, and just can't get it quite right. Any ideas? Thanks.
I just need a button or link there that users can click on to close the window.
Re: Javascript Box
Posted: Fri Dec 20, 2013 7:06 am
by MikuzA
I guess you could just re-use the togglepopup inside the div, like this>
Code: Select all
<script type="text/javascript">
function togglePopup(box){
var popupBox = document.getElementById(box);
if(popupBox.style.display == "block"){
popupBox.style.display = "none";
} else {
popupBox.style.display = "block";
}
}
</script>
<a target="_parent" onmousedown="togglePopup('popbox1')">[Access Store]</a>
<div class="popupBox" id="popbox1" style="display: none;">
<div class="boxbody">
<div class="boxheader">
************</br>
[Store ACCESSED >> Buy stuff here YEAH]</br>
Press X to exit store ->
<a target="_parent" onmousedown="togglePopup('popbox1')">[X]</a></br>
</div>
</div>
Or did I understand the problem wrong

Re: Javascript Box
Posted: Fri Dec 20, 2013 7:45 am
by Epiales
MikuzA wrote:I guess you could just re-use the togglepopup inside the div, like this>
Code: Select all
<script type="text/javascript">
function togglePopup(box){
var popupBox = document.getElementById(box);
if(popupBox.style.display == "block"){
popupBox.style.display = "none";
} else {
popupBox.style.display = "block";
}
}
</script>
<a target="_parent" onmousedown="togglePopup('popbox1')">[Access Store]</a>
<div class="popupBox" id="popbox1" style="display: none;">
<div class="boxbody">
<div class="boxheader">
************</br>
[Store ACCESSED >> Buy stuff here YEAH]</br>
Press X to exit store ->
<a target="_parent" onmousedown="togglePopup('popbox1')">[X]</a></br>
</div>
</div>
Or did I understand the problem wrong

Nope, that works like a charm LOL! Thanks much!
Re: Javascript Box
Posted: Fri Dec 20, 2013 9:07 am
by Epiales
Final result.. Thank you!
Just getting the boxes up there for now. Will format them later

Re: Javascript Box
Posted: Fri Dec 20, 2013 12:24 pm
by Epiales
Okay, another issue.
As you can see, the box is working fine when you click on store. Now I"m having issue of having the buy items php page go back to the actual popup instead of the store.php. Is there a way to do this?
I had it working when I just used the store.php instead of the popup and it worked great; returned and all. But not sure about having it return to the popup. There should be someway to make a command on the popup window to make it stay on that window to purchase the item. A function or something?
Thanks
*edited*
I also had it working with the default javascript popup features, but this is custom popup with css and different, so not sure how to make it work

Re: Javascript Box
Posted: Fri Dec 20, 2013 12:53 pm
by Chris
Ajax.
Check out jQuery.
Re: Javascript Box
Posted: Fri Dec 20, 2013 12:59 pm
by Epiales
By the way, this is my buy item php
Code: Select all
<?php
$id = $_SESSION['userid'];
$randid=$_GET['randid'];
$sql = "SELECT * FROM store WHERE randid='$randid'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
if ($stats_gold < $row['price'])
{
echo "You do not have enough Gold for this purchase!";
echo "<center><a href='index.php'>Go Back</center>";
exit;
}
}
$id = $_SESSION['userid'];
$randid=$_GET['randid'];
$sql = "SELECT * FROM store WHERE randid='$randid'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$name = $row['name'];
$stats1 = $row['stat'];
$statadd = $row['statadd'];
$type = $row['type'];
$price = $row['price'];
$randid2 = rand(1000,999999999);
if ($stats_location != $row['location']) {
echo "<br><br><span id='errormess'><big><center><font color='lime'> You are not high enough level to purchase this item!</center><br></span></big></font>";
} else {
$sql = "INSERT INTO inventory (id, name, stats, statadd, randid,type) VALUES ('$id','$name','$stats1',$statadd,$randid2,'$type')";
$query = mysqli_query($db_conx, $sql);
$sql = "UPDATE stats set gold=gold-'$price' WHERE id = '$_SESSION[userid]'";
$query = mysqli_query($db_conx, $sql);
echo "<br><br><span id='errormess'><big><center><font color='lime'> $name Purchased</center><br></span></big></font>";
}}
?>
<meta http-equiv="refresh" content="1;url=store.php">
If you notice, it does it's thing in the database and then it auto returned back to the store after giving a successful message. Just need to figure out how to make it go back to the original popup. I'll look into Chris, thanks!
Re: Javascript Box
Posted: Fri Dec 20, 2013 1:25 pm
by Chris
From what I understand you want to get PHP to run the database query whilst staying to the same webpage.
To achieve this Ajax is needed.
http://api.jquery.com/jQuery.ajax/
Re: Javascript Box
Posted: Fri Dec 20, 2013 2:21 pm
by Epiales
Chris wrote:From what I understand you want to get PHP to run the database query whilst staying to the same webpage.
To achieve this Ajax is needed.
http://api.jquery.com/jQuery.ajax/
Well, the issue I'll be running into is that there will be around 20 or so links or graphics that will have these popups, and I don't think I need to have all the code for all the popups written on the same page? That's why I was wondering if there was a function I could created that would allow me to use a different page, but yet go back to the popup; since I'll have very many of them.
*edited* LMAO, that's about the worst grammar I've ever used

*
Re: Javascript Box
Posted: Sun Dec 22, 2013 9:46 pm
by Epiales
Okay, I can't figure out how to make it work, so I'll ask if it would make any difference to have everything on one page? Would that eventually make the game slow and cause issues? Or will it be okay on one page?