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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Not Showing Integer

    I changed some things and am doing this for someone else as well for his site. I have the shownames showing correctly in the dropdown however it's not putting the integer into the readonly input field. Anyone know why?


    Here's my form:
    PHP Code:
    <?php
    print '<form action="setupshow.php" method="post" name="myForm">';
    print 
    '<tr><td>Show Name:</td><td><select name="showname" id=\"names\" onChange="ajaxGet();"><option value="">Select a Name</option>';
    $query 'SELECT showname FROM shownames ORDER BY showname';
    $result mysql_query($query);
    while (
    $row mysql_fetch_assoc($result))
    {
    print 
    "<option value=\"{$row['showname']}\">{$row['showname']}</option>\r";
    }         
    print 
    '</select></td></tr>';
    print 
    '<tr><td>Show Label:</td><td><input name="showlabel" id="label" type="text" readonly="true" size="5"></td></tr>';
    print 
    '<tr><th colspan=2><input name="submit" type="submit" value="Submit"><input name="sumbitted" type="hidden" value="TRUE"></th></tr></table></form>';
    ?>

    Here's my javascript code:
    Code:
    <script type="text/javascript">
    function ajaxGet()
    
    {
    
       var xmlHttp;
    
       try
    
       {
    
            // Firefox, Opera 8.0+, Safari
    
            xmlHttp=new XMLHttpRequest();
    
       }
    
       catch (e)
    
         {
    
            // Internet Explorer
    
            try
    
           {
    
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    
           }
    
            catch (e)
    
           {
    
              try
    
                {
    
                   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    
                }
    
              catch (e)
    
                {   
    
                   alert("Your browser does not support AJAX!");
    
                   return false;
    
                }
    
           }
    
       }
    
       xmlHttp.onreadystatechange=function()
    
       {
    
            if(xmlHttp.readyState==4)
    
           {
    
                document.getElementById('shownam').innerHTML = xmlHttp.responseText;
             ajaxGetL();
    
           }
    
       }
    
       //alert("Selected: " + document.getElementById("ajax1").value);
    
       xmlHttp.open("GET","showAjax.php?type=" + document.getElementById("ajax1").value + "&rand=" + Math.random(),true);
    
       xmlHttp.send(null);
    
    }
    
    function ajaxGetL()
    
    {
       //alert("CALLED");
       var xmlHttp;
    
       try
    
       {
    
            // Firefox, Opera 8.0+, Safari
    
            xmlHttp=new XMLHttpRequest();
    
       }
    
       catch (e)
    
         {
    
            // Internet Explorer
    
            try
    
           {
    
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    
           }
    
            catch (e)
    
           {
    
              try
    
                {
    
                   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    
                }
    
              catch (e)
    
                {   
    
                   alert("Your browser does not support AJAX!");
    
                   return false;
    
                }
    
           }
    
       }
    
       xmlHttp.onreadystatechange=function()
    
       {
    
            if(xmlHttp.readyState==4)
    
           {
    
                document.getElementById('label').value = xmlHttp.responseText;
    
           }
    
       }
    
       //alert("Selected: " + document.getElementById("ajax1").value);
    
       xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true);
    
       xmlHttp.send(null);
    }
    </script>

    Here's my ajax page:
    PHP Code:
    <?php

    require('database.php');

    if(isset(
    $_GET['label']))
    {
       
    $label mysql_real_escape_string($_GET['label'],$link);

       
    $res mysql_query("SELECT `showlabel` FROM `shownames` WHERE `showname` = '".$label."' ORDER BY `showlabel` DESC LIMIT 1;") or die("ERROR 1");
       
       
    $list mysql_fetch_assoc($res);
       
       echo 
    $list['showlabel']+1;
    }

    ?>

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    I think the problem lies in that you're not getting the selected "Show Name" properly. The line:
    Code:
    xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true);
    should be something like:
    Code:
    var names = document.getElementById("names");
    xmlHttp.open("GET","showAjax.php?label=" + names.options[names.selectedIndex].value + "&rand=" + Math.random(),true);
    Also your ajax function calls a second ajax function, which I don't think is necessary, but perhapsyou haven't shown us all the code or was it just for testing?

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    That didn't work.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    On closer inspection of your code you appear to have some unwanted backslashes, so you may also want to change this line:
    PHP Code:
    print '<tr><td>Show Name:</td><td><select name="showname" id=\"names\" onChange="ajaxGet();"><option value="">Select a Name</option>'
    to this:
    PHP Code:
    print '<tr><td>Show Name:</td><td><select name="showname" id="names" onChange="ajaxGet();"><option value="">Select a Name</option>'
    Also, in your javascript you are trying to access some html elements that you haven't created(at least in the code you posted), such as; "ajax1" and "shownam".


  •  

    Posting Permissions

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