By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Grab ElementbyID from innerhtml

P: n/a
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").innerHTM L =
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.

Jun 29 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a


fm************@gmail.com wrote:

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?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 29 '06 #2

P: n/a
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").innerHTM L =
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.
Martin Honnen wrote:
fm************@gmail.com wrote:

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?
--

Martin Honnen
http://JavaScript.FAQTs.com/


Jun 29 '06 #3

P: n/a


fm************@gmail.com wrote:

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

Can you answer that:
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?


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 29 '06 #4

P: n/a
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() ;
Martin Honnen wrote:
fm************@gmail.com wrote:

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

Can you answer that:
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?


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Jun 29 '06 #5

P: n/a


fm************@gmail.com wrote:

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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 30 '06 #6

P: n/a
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!
Martin Honnen wrote:
fm************@gmail.com wrote:

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?

--

Martin Honnen
http://JavaScript.FAQTs.com/


Jun 30 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.