Javascript Box

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Javascript Box

Post 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.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Javascript Box

Post 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 :oops:
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post 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 :oops:
Nope, that works like a charm LOL! Thanks much!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post by Epiales »

Final result.. Thank you!

Just getting the boxes up there for now. Will format them later

Image
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post 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 :( :( :( :( :(
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Javascript Box

Post by Chris »

Ajax.

Check out jQuery.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post 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!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Javascript Box

Post 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/
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post 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 :lol: :lol: :lol: :lol: *
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript Box

Post 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?
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”