The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mike7418 (6) [Avatar] Offline
#1
I am using the double combo example as a base for a project I am working on. First off, I am programming in PHP not .net. I have rewritten the XML builder page "DoubleComboXML.php", the XML is working correctly.

I am not really using it as a double combo though. What I have is a calendar on the form. Click the date on the calendar, it populates the date field, then what I want is to list the available timeslots on that date in a dropdown called Timeslot.

My problem is that I am getting "this.req.responseXML has no properties" I have tried a few diffent things in the javascript but nothing has worked. I hard coded the strParams to "q="+oElem+"&f=Form1&e=sTimeslot". oElem is actually the selected date text(i.e 6-21-2007), since it is a link instead of a dropdown. So I am running it on an onclick.

Anyone have any suggestions?
Thanks,
Mike
Pascarello (208) [Avatar] Offline
#2
Re: Double combo Chapter 9 problems
Take a look at a blog: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html

If you look at the responseText do you get what you expect?

Eric

Message was edited by:
Pascarello
mike7418 (6) [Avatar] Offline
#3
Re: Double combo Chapter 9 problems
I do not see a responseText anywhere in the net.js or the 2 functions in the example code. All I see is the responseXML. On the line that is breaking.

What I have done is just before the line that throws the error I did alert(this); which returned [Object] then alert(this.req); which returned [XMLHttpRequest] then I added this.req.responseXML which returned null.

Apparently it is not reading the XML doc?

My PHP code for the XML doc is as follows
<?php <br /> require_once('config.php');
$conn = new mysqli(HOST, USERNAME, PASSWORD, SCHEMA);
$strQuery = $_REQUEST['q'];
$strForm = $_REQUEST['f'];
$strElem = $_REQUEST['e'];
$sDate = "SELECT * FROM flightTimeslot
WHERE sDate = '".dateToDatabase($strQuery)."'";
$sTime = "SELECT * FROM flightTimeslot ORDER BY tStartTime ASC";
$dL = $conn->query($sDate);
$aL = $conn->query($sTime);
@$d = mysqli_fetch_array($dL);
print_r($d['tID']);
$i = 0;
$strXML = new XMLWriter();
$strXML->openMemory();
$strXML->setIndent(true);
$strXML->setIndentString(" "smilie;
$strXML->startDocument('1.0', 'UTF-8');// xml version=/"1.0/"
$strXML->startElement('selectChoice'); // <selectChoice>
$strXML->startElement('selectElement'); // <selectElement>
$strXML->writeElement('formName',$strForm); // <formName>NAME</formName>
$strXML->writeElement('formElement', $strElem); // <formElement>formfield<?formElement>
$strXML->endElement(); // </selectElement>

while ($a = mysqli_fetch_array($aL)) {
if (is_array($d['tID']) && !in_array($a['tID'], $d['tID'][$i])) {
$strXML->startElement('entry');
$strXML->writeElement('optionText', $a['tStartTime'].' - '.$a['tEndTime']);
$strXML->writeElement('optionValue', $a['tID']);
$strXML->endElement();
//print $a['tID'][$i];
} else {
$strXML->startElement('entry');
$strXML->writeElement('optionText', $a['tStartTime'].' - '.$a['tEndTime']);
$strXML->writeElement('optionValue', $a['tID']);
$strXML->endElement();
//print $a['tID'][$i];
}
$i++;
}
$strXML->endElement(); // </selectChoice>
$return = $strXML->outputMemory(true);
print $return;
?>
Pascarello (208) [Avatar] Offline
#4
Re: Double combo Chapter 9 problems
When I said to check the responseText I wanted you to do exactly what you were doing with the other alerts. It would be:

alert(this.req.responseText);

In my last post above I had a link there that showeed you how to debug this error. You have an invalid XML document. You are not setting the Content Type of the page which was #1 if I remember correctly.

If I remember correctly php is something like <?php header('Content-Type: text/xml'); ?>

Eric
mike7418 (6) [Avatar] Offline
#5
Re: Double combo Chapter 9 problems
Eric
Ah yes! I believe that got me past my stuck spot. I am seeing exactly what I was expecting.

I changed the alert(this.req.responseXML); to alert(this.req.responseText); and Added the header("Content-Type:text/xml");

But it is not building the dropdown yet? I'll work on that later

Thanks for you help on this
Mike
mike7418 (6) [Avatar] Offline
#6
Re: Double combo Chapter 9 problems
My PHP XML output that I get from the alert(this.req.responseText); looks like this:
<?xml version="l.0" encoding="UTF-8"?> <selectChoice>
<selectElement:>
<formName>Form1 </formName>
<formElem >sTimeslot </formElem > </selectElement>
<entry>
<optionText>08:00 AM – 09:00 AM</optionText>
<optionValue>1 </optionValue>
</entry>
<entry>
<optionText>09:00 AM - 10:00 AM</optionText>
<optionValue >2 </optionValue >
</entry>
<entry>
<optionTexk>10:00 AM – 11:00 AM</optionText>
<optionValue>3</optionValue>
</entry>
<entry>
<optionText>11:00 AM – 12:00 PM</optionText>
<optionValue >4 </optionValue >
</entry>
<entry>
<optionText>12:00 PM – 01:00 PM</optionText>
<optionValue >5 </optionValue > </entry>
</selectChoice>

But now I have "xSel.childNodes[0].firstchild has no properties" This is on the line that is looking for "formName" I set an alert alert(xSel.childNodes[0].firstChild); and get null in the message. So I am stuck here.

Thanks again,
Mike
Pascarello (208) [Avatar] Offline
#7
Re: Double combo Chapter 9 problems
If you open this php/xml directly in the browser. Put the url in the address bar, does the xml render correctly? If there is an error the browser will point out the error in the xml. [Make sure you set the content type like I mentioned above]

If it renders correctly try doing

alert(this.req.responseXML.getElementsByTagName("entry").length);


Eric
mike7418 (6) [Avatar] Offline
#8
Re: Double combo Chapter 9 problems
It does open with out any errors:
http://www.helicopterco.com/admin/includes/php/DoubleComboXML.php?q=6-21-2007&f=Form1&e=sTimeslot

And alert(this.req.responseXML.getElementsByTagName("entry").length); returns 5
I set this to look at selectElement and it returned 1.

I really appreciate all of your help
Mike
Pascarello (208) [Avatar] Offline
#9
Re: Double combo Chapter 9 problems
Basic idea:

var xmlDoc = this.req.responseXML.documentElement;

var sel = xmlDoc.getElementsByTagName("selectElement")[0];
var formName = sel.childNodes[0].nodeValue;
var elemName = sel.childNodes[1].nodeValue;

Eric
mike7418 (6) [Avatar] Offline
#10
Re: Double combo Chapter 9 problems
I found something that works, though it may not be the best solution, it does work
function FillDropDown(){
//alert(this.req.responseText);
var xmlDoc = this.req.responseXML.documentElement;
var xSel = xmlDoc.getElementsByTagName('selectElement')[0];
//alert(this.req.responseXML.getElementsByTagName("entry").length);
//alert(xSel.childNodes[0].firstChild);
var strFName = xSel.getElementsByTagName('formName')[0].firstChild.nodeValue;
var strEName = xSel.getElementsByTagName('formElem')[0].firstChild.nodeValue;


var objDDL = document.forms[strFName].elements[strEName];
objDDL.options.length = 0;

var xRows = xmlDoc.getElementsByTagName('entry');
for(i=0;i<xRows.length;i++){ >
var theText = xRows[i].getElementsByTagName('optionText')[0].firstChild.nodeValue;
var theValue = xRows[i].getElementsByTagName('optionValue')[0].firstChild.nodeValue;
var option = new Option(theText, theValue);
objDDL.options.add(option,
objDDL.options.length);
}
}

Again, Thanks for the help!
Mike
davecrane (149) [Avatar] Offline
#11
Re: Double combo Chapter 9 problems
Hi Mike, Eric,

I generally tell folk to use getElementsByTagName() rather than firstChild when parsing XML docs, because some browsers (aka Firefox) will treat any whitespace in pretty-printed/indented XML as a textnode element, whereas IE will ignore it. (FWIW, I think FF is being technically correct here, but IE is more pragmatic/intuitive.) I suspect that's why your problems cleared up when you switched coding tactics. You can get away with firstChild on the formName elements, because there's no indentation there.

Cheers,

Dave