Grab ElementbyID from innerhtml

F

fmdevelopertim

New to AJAX so sorry if this is simple.

Have a page that gives the user a list to select a brand. Based on the
brand selected it shows a list of sizes available using the following
code:

function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("serverResponse").innerHTML =
xmlHttp.responseText;
}
}
}

The next step is show a list of all items available that match that
brand and size. Using the following code to grab the values selected:

function createQueryString2() {
var Brand = document.getElementById("Brand").value;
var Size = document.getElementById("size").value;

var queryString = "brand=" + Brand + "&size=" + Size;

return queryString;
}

The page works exactly as expected in FireFox, but IE is not capturing
the size element from the innerHTML. Added display vaiable functions to
the PHP page that is being rendered and the brand variable is there,
the size variable is not.

Thanks for any help.
 
M

Martin Honnen

function createQueryString2() {
var Brand = document.getElementById("Brand").value;
var Size = document.getElementById("size").value;

var queryString = "brand=" + Brand + "&size=" + Size;

return queryString;
}

The page works exactly as expected in FireFox, but IE is not capturing
the size element from the innerHTML. Added display vaiable functions to
the PHP page that is being rendered and the brand variable is there,
the size variable is not.

I can only guess from the name of that function that you somewhere call
it to create a querystring for a HTTP GET request URL.
What do you mean by "IE is not capturing the size element from the
innerHTML"? Do you create the element with id="size" by assigning to the
innerHTML of another element? Do you get a script error on
document.getElementById("size").value
with IE? If there is no element with id="size" then that expression
should give a script error as then getElementById returns null and you
can't access .value on null. Do you get a script error?
 
F

fmdevelopertim

Full Java below:

var xmlHttp;

function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

function createQueryString() {
var Brand = document.getElementById("Brand").value;

var queryString = "brand=" + Brand;

return queryString;
}

function doRequestUsingGET() {
createXMLHttpRequest();

var queryString = "response.php?";
queryString = queryString + createQueryString() ;
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("Post", queryString, true);
xmlHttp.send(null);
}

function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("serverResponse").innerHTML =
xmlHttp.responseText;
}
}
}

function createQueryString2() {
var Brand = document.getElementById("Brand").value;
var Size = document.getElementById("size").value;

var queryString = "brand=" + Brand + "&size=" + Size;

return queryString;
}

function doRequestUsingGET2() {
createXMLHttpRequest();

var queryString = "listing.php?";
queryString = queryString + createQueryString2() ;
xmlHttp.onreadystatechange = handleStateChange2;
xmlHttp.open("Post", queryString, true);
xmlHttp.send(null);
}

function handleStateChange2() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("available").innerHTML =
xmlHttp.responseText;
}
}
}


The page result.php just builds a pull down list - '<select id="size"
onchange="doRequestUsingGET2();" name="size">

I need to grab the value of <select id="Brand"
onchange="doRequestUsingGET();" name="Brand" tabindex="1"> (working
well on all browsers) and the value of Size from the innerhtml call.

These 2 values are used in listing.php which builds a table of the
results.
 
M

Martin Honnen

function createQueryString2() {
var Brand = document.getElementById("Brand").value;
var Size = document.getElementById("size").value;


Can you answer that:

If there is no script error then IE finds the element just fine by its
id. Thus if there is no script error then the problem is not with
getElementById.
 
F

fmdevelopertim

No script error.

I display the two variables in the PHP file and it displays:

Selected Brand is 19
Selected size is

The size variable is empty. It is being passed as:

var queryString = "brand=" + Brand + "&size=" + Size;
var queryString = "listing.php?";
queryString = queryString + createQueryString2() ;
 
M

Martin Honnen

I display the two variables in the PHP file and it displays:

Selected Brand is 19
Selected size is

The size variable is empty. It is being passed as:

var queryString = "brand=" + Brand + "&size=" + Size;
var queryString = "listing.php?";
queryString = queryString + createQueryString2() ;

Hard to tell without seeing a test case. Is the element with id="size" a
single or multiple select element? Does it render properly? What does
document.getElementById('size').selectedIndex
give?
 
F

fmdevelopertim

Thanks for the reply - I figured it out based on your comments. The
list rendered correctly but the value element was not correctly
defined.

I greatly appreciate your assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top