Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:12:38+00:00 2026-06-18T01:12:38+00:00

This is a tough one.. I am attempting to use ajax for the first

  • 0

This is a tough one.. I am attempting to use ajax for the first time. basically upon selecting an option from the first field, js and xml run a php script which creates the next dropdown based of of information it pulls from an SQL table. Surprisingly everything works pretty well, for my first attempt. the problem comes when you run the final query the variable that should be posted over ($_POST['ports'];) evaluates to a single white space character, not the value selected in the tag. time for the code:

html:

<h1>Enter port data to set how your table will look</h1>
<select style="width:150px;" onChange="showUser(this.value)">

<option value="">Select A Table Type</option>
<option value="option1">option1</option>
<option value="247">Custom</option>
</select>
<br>
<div id="select2">
</div>

javascript:

function showUser(str){
document.getElementById('hide').style.display='none';
document.getElementById('select2').innerHTML="";
if(str===""){
    document.getElementById('hide').style.display='none';
    document.getElementById('select2').innerHTML="";
    return;
}

if(str==="247"){
    document.getElementById('hide').style.display='block';
    return;
}

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

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

//set up return
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("select2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethtml.php?q="+str,true);
xmlhttp.send();
}

gethtml.php

//include connection
include 'log.php';

//get vars
$q=$_GET['q'];

//make the query
$sql = "SELECT DISTINCT Model 
FROM tbl
WHERE Manufacturer = '".$q."'";

//make the new box
echo '<select name="ports" style="width:150px;">';
echo '<option>Select A Port Total</option>';
$i=1;
foreach($conn->query($sql) as $row) {
echo $row['Model'];
echo '<option value="'.$row['Model'].'">'.$row['Model'].'</option>';
$i++;
}
echo "</select>";

so, everything is sent to gethtml.php. the query runs correctly, the <select> box is there, however there seems to be an error with the <select> part of it, and i just cant figure out what that is. Here is a snippet from the submission php the runs after you submit the form that the <select> is messing up on.

echo "<pre>";print_r($_POST);echo"</pre>";

which outputs

Array
(
[ports] => 
)

I know you can’t tell, but when i highlight that bit, there is a whitespace character there, i even ran it through an isset() to see it i was right and there is a character there.

here is an image of the xml created html when viewed with firebug:

firebug

Anyone have any ideas? This is very frustrating.. obviously, the firebug image is showing it not looking the way it should… if you guys need any more information please just ask

If its worth noting, im using chrome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:12:39+00:00Added an answer on June 18, 2026 at 1:12 am

    you are not posting your ajax request.

    xmlhttp.open("GET","gethtml.php?q="+str,true);
    

    you are sending it via get. in php, try print_r($_GET) instead of $_POST and check if you see the right value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a tough one to google for. I have an XML document that's
I am having the hardest time figuring this out, even though it is one
I have tough time making this design decision. I could go with traditional new
I am facing a really tough time doing this. I haven't done much on
I'm attempting to use deftype (from the bleeding-edge clojure 1.2 branch) to create a
Probably just another silly pointer issue from a C newbie. Couldn't figure this one
I am attempting to use JSONP to return an array from PHP to JavaScript.
I'm attempting to use R to merge data columns into one tab-delimited matrix. When
I wonder if anyone knows this one. I was getting a pretty tough error
Extension Link: https://www.dephormation.org.uk/?page=81 This plugin is great. It has one problem though, on pages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.