1 Replies - 526 Views - Last Post: 09 September 2012 - 10:47 AM

#1 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 826
  • Joined: 16-September 09

Storing a variable value in between scripts

Posted 09 September 2012 - 09:15 AM

Hey guys!

So I'm using a greybox on my page. It works great but I'm trying to update the source page with the value from the greybox once it closes. I have the following setup.

1. My Source Page -- "Index"
2. AJAX scripts. These call the PHP, update the table with the info then close the GB.
3. My PHP pages that capture the info and update

Now I have the AJAX for the db update and the index update in the same external js page. I tried making a global variable and using a callback but it didn't do the trick. The callback returns "Undefined" I'm curious if there's a creative way, other than cookies, that I could use to store the data for a few mili-seconds until the page receives the update. I'm ever-learning here so I'm hoping it's just something simple I haven't come across yet.

Just for good measure, here's the code I have
<a href = 'http://mypage.co/beta/scripts-php/GB_pages/add_new_post.php?t=1' onclick='return GB_showCenter("Put it out there!", this.href, 210,465, UpdatePostsDiv)' >

  <meta http-equiv='content-type' content='text/html; charset=windows-1250'>
  <meta name='generator' content='PSPad editor, www.pspad.com'>
    include '/home/users/web/b679/moo.mypageco/beta/scripts-php/build/logged-in/getHeadText.php';           
    <script type='text/javascript' src='http://mypage.co/beta/scripts-js/wire/add_new_post.js'></script>
    <script type='text/javascript'>
      function ClearInput(){
        var X = document.getElementById('myPost');
        X.style.color = '#000';
        X.value = '';        
    <form class='NewPostFrm'>
      <h2>Add<span>to the wire</span></h2>
        $PType = $_GET['t'];
        //1=New 2=Reply 3=New to friends wire
        if($PType == 1){
          $InitMsg = 'Add to the wire...';
        }elseif($PType == 2){
          $InitMsg = 'Add your 2 cents...';
        }elseif($PType == 3){
          $InitMsg = 'Add to their wire...';
        echo "<textarea name='myPost' id='myPost' rows='5' cols='50' onclick = 'ClearInput();'>$InitMsg</textarea>";
      <div class='clear'></div>      
        $p = $_GET['p'];
          $p = $_SESSION['userid'];
        echo "<button class = 'W100'  onclick = 'addPost(\"$p\")' >Create</button>";        
      <div class='clear' ></div>

var PostBody;
function addPost(OwnerID){

  PostBody = document.getElementById("myPost");
  //Check for blank post
  if(!PostBody.value || PostBody.value == "Add to the wire..." || PostBody.value == "Add to their wire..." || PostBody.value == "Add your 2 cents...") parent.parent.GB_hide();
  if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    //if(xmlhttp.readyState==4 && xmlhttp.status==200){
  xmlhttp.open("GET","http://mypage.co/beta/scripts-php/wire/create_new_post.php?oID=OwnerID&pBdy=PostBody", true);

function UpdatePostsDiv(){  
  var PostCon = document.getElementById("MainPostCon");
  PostCon.innerHTML = PostBody + PostCon.innerHTML; 

As always, thanks in advance!!

This post has been edited by guyfromri: 09 September 2012 - 09:17 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Storing a variable value in between scripts

#2 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 130
  • View blog
  • Posts: 837
  • Joined: 25-October 08

Re: Storing a variable value in between scripts

Posted 09 September 2012 - 10:47 AM

If you don't want to use cookies, look into 'localstrorage' using HTML 5 browsers.
See: http://diveintohtml5.info/storage.html
and: http://www.w3schools..._webstorage.asp
or: http://24ways.org/20...5-local-storage
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1