[BNM] Ajax type query

Jason Bailey j.bailey at sussex.ac.uk
Wed Oct 18 16:55:37 BST 2006


Hello,

I'm messing with a form that will produce help text from an xml file based 
on the Onfocus form field. The Ajax request stuff appears to be all 
working. I'm just trying to work out an efficient way of selecting the 
value of one ?sibling? <text> based on the value (?innerhtml?) of another.
I've got some simple XML looking like this:

<?xml version="1.0" ?>
<root>
	<data>
		<row>
			<number>0</number>
			<id>client</id>
			<text>A named individual who can sign off the finished project</text>
		</row>
		<row>
			<number>1</number>
			<id>other_client</id>
			<text>If different from the client.. blah blah</text>
		</row>
	
	</data>
</root>

I want to create a little Ajax JS routine that will display <text> 
depending on the variable that is passed to it.

Most of the Ajax works and I've got an input box like this:

<input type = "text" size = "30" name = "membername" id="client" value = "" 
onfocus="javascript:do_xml(this.id);"/>

So basically the text is to be displayed somewhere when the input box is in 
focus.

My question is how do I select the appropriate text for the given id? I can 
see by looping through and doing some if checks I can get the right <text> 
but have just gone completely blank.

Can I do something where innerhtml of the xml data id field is equal to 
some passed value e.g. Client. I'm guessing I need my javascript to start 
like this (assuming all the other bits work)

function selecttext(id)
{
if (http_request.readyState == 4) {
         if (http_request.status == 200) {

            var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
            // go to row node and search id tag values for id??
            //then choose text value
            // return result for display

}
any help appreciated

Many thanks
Jason



More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service