Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post

    Onload javascript snippet does not post its key/value pairs to php script

    I just wrote a javascript snippet that is supposed to run onload. Firebug shows this snippet doing nothing - literally. It does not post its key/value pairs to its php script. Firebug does not show it calling its php script at all.

    Testing shows the php script works and the "austin" ajax object is created.

    One line of this snippet is highlighted in red in the code shown below.

    Everything else works.

    Please ignore the .html file extensions. Php is told to read these files.

    The 2 snippets at the end that are each enclosed in a clickable function, shown in green are newly written and untested, because their clickable buttons have not been placed on the page by the onload snippet in red that doesn't work.

    Since they are inside a function, instead of executing onload, they should not stop anything else from working. I highlighted them in green just in case they are important.

    Does anyone know what I did wrong with the snippet in red?

    Thank you for your help.

    The code:
    Code:
    
    <!DOCTYPE html>
    
    <html>
    <head>
    <title>Control Panel Side</title>
    <style type="text/css">
    .horizontal ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    }
    
    body {margin: 10em;}
    
    #form {margin: 1em 1em;l}
    
    #answer {
    padding: .2em .2em;
    margin: .5em 0 .5em 0;
    }
    
    .horizontal ul li { 
    display: inline;
    width: 200px;
    height: 50px;
    background: #ccc; 
    text-align: center;
    padding: .3em;
    }
    </style>
    
    <script src="/A2EB891D63C8/avg_ls_dom.js" type="text/javascript"></script><script type="text/javascript"> 
      //Control Panel Side 
      var cathy;
        cathy = new XMLHttpRequest();
       //try { request = new XMLHttpRequest();
       //} catch (e) {
         //if(request=undefined) alert('e.message');
         //}
        //if(request)
        //{
         // alert('Ajax Object Created');
        //}
      var kinley;
        kinley = new XMLHttpRequest();
    
      var dazzle;
        dazzle = new XMLHttpRequest();
    
      var weather;
        weather = new XMLHttpRequest();
    
      var electric;
        electric = new XMLHttpRequest();
     
      var request;
        request = new XMLHttpRequest();
    
      var austin;
        austin = new XMLHttpRequest();
    //-->
    </script>
    </head>
    
    <body>
    
    <div class=horizontal>
    <form >
    <ul id="May120128AM_list" style="display: block;"> 
    
          <li><input type="hidden" id="May120128AM_choose_to_display_or_not_by_clicking_button" name="element_id" value="May120128AM_list"></li>
    
    
          <li><input type="hidden" id="May120128AM" name="apt_time" value="May120128AM"></li>
    
          <li><input type="hidden" name="user_id" id="May120128AM_user_id"  value="202020"/></li>
    
          <li><input type="hidden" name="password" id="May120128AM_password"  value="2"/></li>
    
          <li id="May120128AM_local_time" style=\"display: inline;
                                                  width: 150px;
                                                  height: 50px;
                                                  background: #ccc; 
                                                  text-align: center;
                                                  padding: .3em;"
    
          >8:00 - 8:45 AM</li>
    
          <li id = 'May120128AM_Apt_Time_Shown_Place_Button_To_Hide_Apt_Time_From_Customer_Here' 
    style=\"display: inline;
         width: 200px;
         height: 50px;
         background: #ccc; 
         text-align: center;
         padding: .3em;"
          ></li>
    
    
          <li id = 'May120128AM_Apt_Time_Hidden_Place_Button_To_Show_Apt_Time_To_Customer_Here' style=\"display: inline;
         width: 200px;
         height: 50px;
         background: #ccc; 
         text-align: center;
         padding: .3em;"
          ></li>
    
    
    
    
          <li id = 'May120128AM_Make_Apt_Time_Unavailable_To_Customers' style=\"display: inline;
         width: 200px;
         height: 50px;
         background: #ccc; 
         text-align: center;
         padding: .3em;"
          ></li>
    
    
          <li id = 'May120128AM_Make_Apt_Time_Available_To_Customers' style=\"display: inline;
         width: 200px;
         height: 50px;
         background: #ccc; 
         text-align: center;
         padding: .3em;"
          ></li>
    
    
          <li id = 'May120128AM_Schd_Can' style=\"display: inline;
                                                    width: 200px;
                                                    height: 50px;
                                                    background: #ccc; 
                                                    text-align: center;
                                                    padding: .3em;"
          ></li>
    
          <li id = 'May120128AM_Nt_Avail' style=\"display: inline;
                                                    width: 200px;
                                                    height: 50px;
                                                    background: #ccc; 
                                                    text-align: center;
                                                    padding: .3em;"
          ></li>
    
          <li id = 'May120128AM_Avail' style=\"display: inline;
                                                    width: 200px;
                                                    height: 50px;
                                                    background: #ccc; 
                                                    text-align: center;
                                                    padding: .3em;"
          ></li>
    
    </ul>
    </form>
    </div>
    
    <script type="text/javascript">
        var apt_time = encodeURIComponent(document.getElementById("May120128AM").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        //var password = encodeURIComponent(document.getElementById("May120128AM_password").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
    
        kinley.open("POST", "/cgi-bin/check_apts_onload_with_just_apt_time.html", false);
        kinley.onreadystatechange = function()
        {
           if(kinley.readyState == 4)
           {
              if(kinley.status == 200)
              {
                      var SchdCan = document.getElementById('May120128AM_Schd_Can');
                      var NtAvail = document.getElementById('May120128AM_Nt_Avail');
                      var Avail = document.getElementById('May120128AM_Avail');
    
                  if(kinley.responseText == "available")
                  {   
                     if(SchdCan.innerHTML == '' &&
                        NtAvail.innerHTML == '' &&
                        Avail.innerHTML == '')
                     {
                            SchdCan.innerHTL = '' 
                            NtAvail.innerHTML = '' 
                            Avail.innerHTML = "Available <button id='May120128AM_Click_To_Sch' name='apt_time' value='May120128AM' onClick='clickToSchedule(); return false'>Click Here To Schedule</button>"
                     } 
                     if(SchdCan.innerHTML == '' &&
                        NtAvail.innerHTML == 'not available' &&
                        Avail.innerHTML == '')
                     {
                            SchdCan.innerHTL = '' 
                            NtAvail.innerHTML = '' 
                            Avail.innerHTML = "Available <button id='May120128AM_Click_To_Sch' name='apt_time' value='May120128AM' onClick='clickToSchedule(); return false'>Click Here To Schedule</button>"
                     } 
                     if(SchdCan.innerHTML == '' &&
                        NtAvail.innerHTML == '' &&
                        Avail.innerHTML == "Available <button id='May120128AM_Click_To_Sch' name='apt_time' value='May120128AM'>Click Here To Schedule</button>"
                                             )
                                             
                     {
                            SchdCan.innerHTML = "" 
                            NtAvail.innerHTML = '' 
                            Avail.innerHTML = "Available <button id='May120128AM_Click_To_Sch' name='apt_time' value='May120128AM'>Click Here To Schedule</button>"
                     } 
                  }
                  if(kinley.responseText == "you are scheduled")
                  {
                        
                            SchdCan.innerHTML = "You Are Scheduled <button id='May120128AM_Click_To_Can' name='apt_time' value='May120128AM' onClick = 'clickToCancel(); return false'>Click Here To Cancel</button>"
                      
                  }
                  if(kinley.responseText == "not available")
                  {
                                            
    			NtAvail.innerHTML = 'not available'
    		  
                      
    
                  }  //Closing if(responseText == "")
                  
              }  //Closing if(kinley.status == 200)
              
           }  //Closing if(kinley.readyState==4)
        }  //Closing onreadystatechange function 
        kinley.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        kinley.send(parameters);
    
    </script>
    
    
    
    
    
    
    <script type="text/javascript">
        var apt_time = encodeURIComponent(document.getElementById("May120128AM").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
        austin.open("POST", "/cgi-bin/check_apts_table_to_see_if_this_time_is_available_to_customers_onload.html", false);
        austin.onreadystatechange = function()
        {
           if(austin.readyState == 4)
           {
              if(austin.status == 200)
              {
                  if(austin.responseText == "apt time open")
                  {
                     var available = encodeURIComponent('May120128AM_Make_Apt_Time_Available_To_Customers'); 
                     available.innerHTML = "Apt Time Open <button onClick='clickToMakeThisAptUnavailableToCustomers(); return false'>Block</button>"
                     var unavailable = encodeURIComponent('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
                     unavailable.innerHTML = ""
                  }
                  if(austin.responseText == "apt time blocked")
                  {
                     var unavailable = encodeURIComponent('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
                     unavailable.innerHTML = "Apt Time Blocked <button onClick='clickToMakeThisAptAvailableToCustomers(); return false'>Open</button>"
                  }
              }
           }
        austin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        austin.send(parameters);
    </script>
    
    
    
                 <script type="text/javascript">
                 //CSS - Display Or Not Onload - Start
                 var display = encodeURIComponent(document.getElementById("May120128AM_choose_to_display_or_not_by_clicking_button").value);
                 var parameters = "element_id="+display
                 cathy.open("POST", "/cgi-bin/control_panel_css_check_table_to_determine_if_status_is_display_or_hide_onload.html", false);
                 cathy.onreadystatechange = function()
                 {
                    if(cathy.readyState == 4)
                    {
                      if(cathy.status == 200)
                      {
                           if(cathy.responseText == "block")
                           {
                               var tree = document.getElementById('May120128AM_Apt_Time_Shown_Place_Button_To_Hide_Apt_Time_From_Customer_Here');  
                               tree.innerHTML = "Apt Shown <button onClick='clickToHideApt(); return false'>Hide Apt</button>";
                               var bush = document.getElementById('May120128AM_Apt_Time_Hidden_Place_Button_To_Show_Apt_Time_To_Customer_Here');
                               bush.innerHTML = '';
                           }
    
                           if(cathy.responseText == "none")
                           {
                               var tree = document.getElementById('May120128AM_Apt_Time_Shown_Place_Button_To_Hide_Apt_Time_From_Customer_Here');  
                               tree.innerHTML = "";
                               var bush = document.getElementById('May120128AM_Apt_Time_Hidden_Place_Button_To_Show_Apt_Time_To_Customer_Here');
                               bush.innerHTML = "Apt Hidden <button  onClick='clickToShowApt(); return false'>Show Apt</button>";
                           }
    
                      }
                    }
                 }
                 cathy.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                 cathy.send(parameters);
                 //CSS - Display Or Not Onload - End 
                 </script>
    
    
    
    
     
    
    
    
    <script type="text/javascript"><!--Begin Click To Cancel//-->
    <!--
    function clickToCancel()
    {
        var apt_time = encodeURIComponent(document.getElementById("May120128AM_Click_To_Can").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
    
        weather.open("POST", "/cgi-bin/click_to_cancel_this_apt.html", false);
        //request.onreadystatechange = checkData;
        weather.onreadystatechange = function()
        {
           if(weather.readyState == 4)
           {
              if(weather.status == 200)
              {
                      var SchdCan = document.getElementById('May120128AM_Schd_Can');
                      var NtAvail = document.getElementById('May120128AM_Nt_Avail');
                      var Avail = document.getElementById('May120128AM_Avail');
    
                  //if(weather.responseText == 'available')
                  //{   
                            SchdCan.innerHTML = '' 
                            NtAvail.innerHTML = '' 
                            Avail.innerHTML = "Available <button id='May120128AM_Click_To_Sch' name='apt_time' value='May120128AM' onClick='clickToSchedule(); return false'>Click Here To Schedule</button>"
                  //} 
                  
              }  //Closing if(weather.status == 200)
              
           }  //Closing if(weather.readyState==4)
        }  //Closing onreadystatechange function 
        weather.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        weather.send(parameters);
    }
    //-->
    </script><!--//End Click To Cancel//-->
    
    
    
    
    
    
    
    
    
    
    
    
    
                 <script type="text/javascript">
                 function clickToHideApt()
                 {
                       var display = encodeURIComponent(document.getElementById("May120128AM_choose_to_display_or_not_by_clicking_button").value);
                       var parameters = "element_id="+display
                       electric.open("POST", "/cgi-bin/control_panel_css_click_to_insert.html", false);
                       electric.onreadystatechange = function()
                       {
                          if(electric.readyState == 4)
                          {
                              if(electric.status == 200)
                              {
    
                                 var show = document.getElementById('May120128AM_Apt_Time_Hidden_Place_Button_To_Show_Apt_Time_To_Customer_Here');
                                 show.innerHTML = "Apt Hidden <button  onClick='clickToShowApt(); return false'>Show Apt</button>" 
                                 
                                 var bush = document.getElementById('May120128AM_Apt_Time_Shown_Place_Button_To_Hide_Apt_Time_From_Customer_Here');
                                
                                 bush.innerHTML = ''
    			  }            
                          }
                            
                       }
                       electric.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                       electric.send(parameters);
                 }
                 </script>  
    
    
    
    
    
                 <script type="text/javascript">
                 function clickToShowApt()
                 {
                       var display = encodeURIComponent(document.getElementById("May120128AM_choose_to_display_or_not_by_clicking_button").value);
                       var parameters = "element_id="+display
                       electric.open("POST", "/cgi-bin/control_panel_css_click_to_delete.html", false);
                       electric.onreadystatechange = function()
                       {
                          if(electric.readyState == 4)
                          {
                              if(electric.status == 200)
                              {
                                 var house = document.getElementById('May120128AM_Apt_Time_Shown_Place_Button_To_Hide_Apt_Time_From_Customer_Here');
                                 house.innerHTML = "Apt Shown <button onClick='clickToHideApt(); return false'>Hide Apt</button>"
                                 var hoop = document.getElementById('May120128AM_Apt_Time_Hidden_Place_Button_To_Show_Apt_Time_To_Customer_Here');
                                 hoop.innerHTML = '';
                              }
                          }
                       }
                       electric.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                       electric.send(parameters);
                 }
    </script>
    
    
    
    
    
    
    <script type="text/javascript">
    function clickToMakeThisAptAvailableToCustomers()
    {
        var apt_time = encodeURIComponent(document.getElementById("May120128AM").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
        kinley.open("POST", "/cgi-bin/click_to_make_this_apt_time_available_to_customers.html", false);
        kinley.onreadystatechange = function()
        {
           if(kinley.readyState == 4)
           {
              if(kinley.status == 200)
              {
           var available = encodeURIComponent(getElementById('May120128AM_Make_Apt_Time_Available_To_Customers'); 
           available.innerHTML = "Apt Time Open <button onClick='clickToMakeThisAptUnavailableToCustomers(); return false'>Click To Block</button>"
           var unavailable = encodeURIComponent(getElementById('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
           unavailable.innerHTML = ""
              }
           }
        }
        kinley.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        kinley.send(parameters);
    }
    </script><!--clickToMakeThisAptAvailableToCustomers - End//-->
    
    
    
    
    
    
    
    
    <script type="text/javascript">
    function clickToMakeThisAptUnavailableToCustomers()
    {
        var apt_time = encodeURIComponent(document.getElementById("May120128AM").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
        kinley.open("POST", "/cgi-bin/click_to_make_this_apt_time_unavailable_to_customers.html", false);
        kinley.onreadystatechange = function()
        {
           if(kinley.readyState == 4)
           {
              if(kinley.status == 200)
              {
           var unavailable = encodeURIComponent(getElementById('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
           unavailable.innerHTML = "Apt Time Blocked <button onClick='clickToMakeThisAptAvailableToCustomers(); return false'>Click To Open</button>"
           var available = encodeURIComponent(getElementById('May120128AM_Make_Apt_Time_Available_To_Customers'); 
           available.innerHTML = ""
              }
           }
        }
        kinley.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        kinley.send(parameters);
    }
    </script><!--clickToMakeThisAptUnavailableToCustomers - End//-->
    
    </body>
    
    
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
    <script type="text/javascript">
    austin = new XMLHttpRequest;
        var apt_time = encodeURIComponent(document.getElementById("May120128AM").value);
        var userid = encodeURIComponent(document.getElementById("May120128AM_user_id").value);
        var parameters = "apt_time="+apt_time+"&user_id="+userid
        austin.open("POST", "/cgi-bin/check_apts_table_to_see_if_this_time_is_available_to_customers_onload.html", false);
        austin.onreadystatechange = function(){
           if(austin.readyState == 4){
              if(austin.status == 200){
                  if(austin.responseText == "apt time open"){
                     var available = encodeURIComponent('May120128AM_Make_Apt_Time_Available_To_Customers'); 
                     available.innerHTML = "Apt Time Open <button onClick='clickToMakeThisAptUnavailableToCustomers(); return false'>Block</button>"
                     var unavailable = encodeURIComponent('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
                     unavailable.innerHTML = ""
                  }
                  if(austin.responseText == "apt time blocked"){
                     var unavailable = encodeURIComponent('May120128AM_Make_Apt_Time_Unavailable_To_Customers'); 
                     unavailable.innerHTML = "Apt Time Blocked <button onClick='clickToMakeThisAptAvailableToCustomers(); return false'>Open</button>"
                  }
              }
           }
        }// you forgot this
        austin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        austin.send(parameters);
    
    </script>

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •