473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grab ElementbyID from innerhtml

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 handleStateChan ge() {
if(xmlHttp.read yState == 4) {
if(xmlHttp.stat us == 200) {
document.getEle mentById("serve rResponse").inn erHTML =
xmlHttp.respons eText;
}
}
}

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 createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("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
6 7541


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

function createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("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.getEle mentById("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
Full Java below:

var xmlHttp;

function createXMLHttpRe quest() {
if (window.ActiveX Object) {
xmlHttp = new ActiveXObject(" Microsoft.XMLHT TP");
}
else if (window.XMLHttp Request) {
xmlHttp = new XMLHttpRequest( );
}
}

function createQueryStri ng() {
var Brand = document.getEle mentById("Brand ").value;

var queryString = "brand=" + Brand;

return queryString;
}

function doRequestUsingG ET() {
createXMLHttpRe quest();

var queryString = "response.php?" ;
queryString = queryString + createQueryStri ng() ;
xmlHttp.onready statechange = handleStateChan ge;
xmlHttp.open("P ost", queryString, true);
xmlHttp.send(nu ll);
}

function handleStateChan ge() {
if(xmlHttp.read yState == 4) {
if(xmlHttp.stat us == 200) {
document.getEle mentById("serve rResponse").inn erHTML =
xmlHttp.respons eText;
}
}
}

function createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("size" ).value;

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

return queryString;
}

function doRequestUsingG ET2() {
createXMLHttpRe quest();

var queryString = "listing.ph p?";
queryString = queryString + createQueryStri ng2() ;
xmlHttp.onready statechange = handleStateChan ge2;
xmlHttp.open("P ost", queryString, true);
xmlHttp.send(nu ll);
}

function handleStateChan ge2() {
if(xmlHttp.read yState == 4) {
if(xmlHttp.stat us == 200) {
document.getEle mentById("avail able").innerHTM L =
xmlHttp.respons eText;
}
}
}
The page result.php just builds a pull down list - '<select id="size"
onchange="doReq uestUsingGET2() ;" name="size">

I need to grab the value of <select id="Brand"
onchange="doReq uestUsingGET(); " 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 createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("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.getEle mentById("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


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

function createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("size" ).value;

Can you answer that:
Do you get a script error on
document.getEle mentById("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
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.ph p?";
queryString = queryString + createQueryStri ng2() ;
Martin Honnen wrote:
fm************@ gmail.com wrote:

function createQueryStri ng2() {
var Brand = document.getEle mentById("Brand ").value;
var Size = document.getEle mentById("size" ).value;

Can you answer that:
Do you get a script error on
document.getEle mentById("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


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.ph p?";
queryString = queryString + createQueryStri ng2() ;


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.getEle mentById('size' ).selectedIndex
give?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 30 '06 #6
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.ph p?";
queryString = queryString + createQueryStri ng2() ;


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.getEle mentById('size' ).selectedIndex
give?

--

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


Jun 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6544
by: RobG | last post by:
I know you aren't supposed to use innerHTML to mess with table structure, but it seems you can't use it just after a table without damaging the containing element. I added a table to a div using createElement methods, then added a bit of extra text using innerHTML, only to find most of the attributes removed from the table. Below is a...
24
2965
by: Randall Arnold | last post by:
I know how to use MSHTML to grab the innerhtml from an html web page, but what if I want to look at elements of a rendered aspx page? Is there any way to do this using the MSHTML DOM object? Thanks, Randall Arnold
8
9409
by: '69 Camaro | last post by:
Perhaps I'm Googling for the wrong terms. Does anyone have links to examples of the syntax necessary to read the HTML on another Web page when that HTML is produced from JavaScript using the document.write( ) method? For a simplified example, I have two Web pages. Page 1 uses JavaScript with the following: htmlData = "<B>This is bold...
9
8646
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at <http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html> need such a lot of tests to find out if innerHTML assignment actually works, instead of just inserting...
11
2368
by: David | last post by:
Hi Everyone, I'm trying to grab all of the elements of a DL, specifically the <a href>'s grouping them by the DD's. I suppose if I can just get them into groups I can get the href's later. The hard part is getting them grouped as explained below. For example... <dl id="dlList">
9
3356
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text = dt.innerHTML + 'new' in Firefox, I get "test textnew"
6
4218
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which exactly matches the contents of the div with one exception. It seems that whenever the code includes a tag which uses the forward slash against the...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.