473,807 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Text to Node

I am attempting to create a set of chained selectors (one <select> uses
AJAX to read values for the next <select>, and so on). My AJAX code
works fine, and returns the text of the entire <select> statement. I
have defined a separate <DIV> for each selector to be created inside
of.

However, what is returned is ONLY text. When I attempt to create second
selector based on the value of the first, the javascript console is
happy to inform me that the first element doesn't exist.

So, if I get this back from the AJAX function:

<select name="selState" >
<option>Alabama </option>
<option>Arizona </option>
....
</select>

How do I convert this to an actual Element, so that is is visible as
part of the document tree?

Jason

/**
This function generates an AJAX request to create a <select> filled
with the state names.
*/
function getStates() {
var docname='ajax.p hp?action=1';
http.open('get' ,docname);
http.onreadysta techange = function() {
if (http.readyStat e == 4) {
var response = http.responseTe xt;
document.getEle mentById('state Select').innerH TML = response;
}
};
http.send(null) ;

}

function getCounties() {
if (document.getEl ementById('selS tate') == null) {
alert('No selState node!');
}
var docname='ajax.p hp?action=1+par am=' +
document.getEle mentById('selSt ate').value;
http.onreadysta techange = function() {
if (http.readyStat e == 4) {
var response = http.responseTe xt;
document.getEle mentById('count ySelect').inner HTML = response;
}
};
}

Oct 5 '05 #1
1 3320
DartmanX wrote:
I am attempting to create a set of chained selectors (one <select> uses
AJAX to read values for the next <select>, and so on). My AJAX code
works fine, and returns the text of the entire <select> statement. I
have defined a separate <DIV> for each selector to be created inside
of.

However, what is returned is ONLY text. When I attempt to create second
selector based on the value of the first, the javascript console is
happy to inform me that the first element doesn't exist.

So, if I get this back from the AJAX function:
The 'X' in 'AJAX' stands for XML, but you aren't using it. You are
trying to build your new select using HTML and innerHTML, which is
bound to fail. Incidentally, ditch 'AJAX' and just call it
XMLHttpRequest, 'cos that's what it is.

You need to parse the returned data and construct your select. Use JSON:

<URL:http://www.crockford.c om/JSON/index.html>
or get the data back as an XML file and parse that using DOM:

<URL:http://developer.apple .com/internet/webcontent/xmlhttpreq.html >
Use the second link and you'll end up working with IE too (I think
your current code will only work in non-IE browsers).

[...]
function getStates() {
var docname='ajax.p hp?action=1';
http.open('get' ,docname);
http.onreadysta techange = function() {
if (http.readyStat e == 4) {
var response = http.responseTe xt;
document.getEle mentById('state Select').innerH TML = response;


Here is where you need to call a function to parse the response and
generate DOM elements, innerHTML doesn't create selects and options
very robustly, if at all.
[...]
--
Rob
Oct 5 '05 #2

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

Similar topics

8
2345
by: Arvid Andersson | last post by:
Hello, I need to convert a string to a number, but the string can contain +,-,* and / as well as parenthesis. For example, if I have the string "30/(6+9)" I would like a function that returned the number 2. I actually wrote a java function that did this a couple of years ago, in school, as an excersise in "binary trees". I lost it, and most of my programming knowledge, but I figured perhaps there is a way to do this easily in python? It...
5
1776
by: Richard Lewis | last post by:
Hello Pythoners, I'm currently writing some Python to manipulate a semi-structured XML document. I'm using DOM (minidom) and I've got working code for transforming the document to HTML files and for adding the 'structured' elements which populate the higher regions of the tree (i.e. near the root). What I have to do next is write some code for working with the 'less structured' elements towards the 'leaf ends' of the tree. These are
1
3078
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value of the second table, etc. Parent varchar 3 Name varchar 60 Code varchar 3 WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
2
6863
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node as a value. Check out the following problem. I want to convert the value in <WpDatesXml> node to have a valid "<" and ">" instead of &lt or &gt format so that I can use this xml for another use. Please help! <NewDataSet> <Table1>
5
12723
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
9
3525
by: keliie | last post by:
Hello (from Access novice), I'm building a switchboard form (using a Treeview object). The treeview is populated by two tables (tblSwitchboardParent and tblSwitchboardChild). Within tblSwitchboardChild, I have a string field called ChildArgument that contains string text of VBA code (e.g., DoCmd.OpenForm "myForm"). When users click on various portions of the Treeview object I want the Tree to either expand or open the report / form.
27
5159
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
4
2132
by: Danny Shevitz | last post by:
Simple question here: I have a multiline string representing the body of a function. I have control over the string, so I can use either of the following: str = ''' print state return True '''
3
2282
by: gayaneducation | last post by:
I need to convert following huge xml file like this ----------------------- <?xml version="1.0" encoding="UTF-8" standalone="no"?> <nodeset> <option value="132.146.3.231" label="132.146.3.231"></option> <option value="122.333.4.444" label="122.333.4.444"></option> </nodeset> -----------------------
0
9721
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9195
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5547
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
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

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.