Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Ajax/php respone problem
New Posts  All Forums:Forum Nav:

Ajax/php respone problem

post #1 of 18
Thread Starter 
index.php

Code:
<script type="text/javascript">
function getDownload(str)
{
if (str=="")
  {
  document.getElementById("downloadsubid").innerHTML="";
  return;
  }

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }

else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("downloadsubid").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","getdownloadsubname.php?q="+str,true);
xmlhttp.send();
return true;
}
</script>

...

<form name="upload" method="post" enctype="multipart/form-data" action="downloads_upload_file_query.php">
                    <table width="100%">
                    <tr>
                            <td>
                                <select name="download_parent_id" onchange="getDownload(this.options[this.selectedIndex].value)">
                                <option value="">Select Catagory</option>
                                <?php
                                $sql = "SELECT * FROM downloads_parent ORDER BY download_parent_id ASC";
                                $result = mysql_query($sql);

                                while($rows = mysql_fetch_array($result))
                                {
                                ?>
                                <option value="<?php echo $rows['download_parent_id']; ?>"><?php echo $rows['download_parent_name']; ?></option>
                                <?php
                                }
                                ?>
                                </select>
                                <br>
                                <div id="downloadsubid"></div>
                            </td>
                        </tr>
                        <tr>
                            <td class="page_text">File Name: <input name="download_name"><br /><br /></td>
                        </tr>
                        <tr>
                            <td class="page_text">File Author: <input name="download_author"><br /><br /></td>
                        </tr>
                        <tr>
                            <td class="page_text">File Location: <input type="file" name="file" id="file"><br /><br /></td>
                        </tr>
                        <tr>
                            <td><input name="Submit" type="submit" value="Upload"></td>
                        </tr>
                    </table>
                </form>
getdownloadsubname.php
Code:
<?php
include ('includes/sqlconnect.php');

$sql2 = "SELECT * FROM downloads_sub WHERE download_parent_id = " . $_GET["q"] . " ORDER BY download_sub_id ASC";
$result2 = mysql_query($sql2);

?>
<select name="downloads_sub_id">
<option>Select Sub Catagory</option>
<?php

while($rows2 = mysql_fetch_array($result2))
{
?>
<option value="<?php echo $rows2['download_sub_id']; ?>"><?php echo $rows2['download_sub_name']; ?></option>
<?php
}
?>
</select>
The drop down menu on the index.php has a dependent value for getdownloadsubname.php which is Q in the response file. In red on index.php is where it is being displayed. I am currently getting no output at all. What am I missing?
Edited by mrsmoke - 8/12/11 at 4:43pm
post #2 of 18
On your select, you have
Code:
onchange="getDownload(this.value)"
which is referring to the <select>'s value attribute which is nothing.
It should be this instead
Code:
onchange="getDownload(this.options[this.selectedIndex].value)"
to get the selected option's value attribute
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #3 of 18
You should be using jQuery for ajax. http://api.jquery.com/jQuery.get
iCode
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K ASUS P8Z68 Deluxe 2X EVGA DS GTX 580 Superclocked SLI CORSAIR Vengeance 8GB (2x4GB) 
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 MAX IOPS Edition ASUS DRW Win 7 Ultimate x64 HP ZR30w 
KeyboardPowerCaseMouse
Logitech Ultra-Thin Illuminated Keyboard COOLER MASTER Silent Pro Gold Series 1000W LIAN LI PC-B25FWB Black Logitech MX518 
  hide details  
Reply
iCode
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K ASUS P8Z68 Deluxe 2X EVGA DS GTX 580 Superclocked SLI CORSAIR Vengeance 8GB (2x4GB) 
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 MAX IOPS Edition ASUS DRW Win 7 Ultimate x64 HP ZR30w 
KeyboardPowerCaseMouse
Logitech Ultra-Thin Illuminated Keyboard COOLER MASTER Silent Pro Gold Series 1000W LIAN LI PC-B25FWB Black Logitech MX518 
  hide details  
Reply
post #4 of 18
Quote:
Originally Posted by SiPex View Post
You should be using jQuery for ajax. http://api.jquery.com/jQuery.get
There is no need to load an entire framework if all you need a couple AJAX calls. jQuery is great but you don't need to use it on every single project. I wouldn't recommend loading jQuery(even if it's from google's api) or any other framework when you can do the same thing with 5 lines of pure javascript and that's the extent of javascript you need.
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #5 of 18
Thread Starter 
Quote:
Originally Posted by Jonowxeno View Post
On your select, you have
Code:
onchange="getDownload(this.value)"
which is referring to the <select>'s value attribute which is nothing.
It should be this instead
Code:
onchange="getDownload(this.options[this.selectedIndex].value)"
to get the selected option's value attribute
I changed the code to your suggestion Jonowxeno. Unfortunately it did not solve the problem. See anything else wrong?
post #6 of 18
Do you have this on a website that I can check?
Do you have firebug for firefox so you can check what is happening with the call?
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #7 of 18
Thread Starter 
I figured it out using firebug what an amazing tool. Thanks for all the help everyone Rep +.
post #8 of 18
That's Great. firebug is great at spotting what's happening, every developer needs it =)
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #9 of 18
Thread Starter 
I have another problem now. The index page is listed in the original post and the same code am having problem with. When the file is uploaded and getdownloadsubname.php is called in the form, $_FILES is not populated on the next page. Any suggestions?
post #10 of 18
Thread Starter 
Anyone?
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Ajax/php respone problem