Re: Re: [PHP-DB] Read file

From: Date: Thu, 20 Nov 2003 17:58:59 +0000
Subject: Re: Re: [PHP-DB] Read file
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31666@lists.php.net to get a copy of this message
OK Error in my last post, the mail reader munged the HTML so if you need as source.... use the XML data below and hopefully the text below will appear as html code ;-) Cheers - Neil <html> <head>
        <title>Demo Hotel Loader</title>
</head> <body onload="populatelist()"> <script language="javascript1.2"> <!-- oxmlDocument = new ActiveXObject("MSXML2.DOMDocument"); oxmlDocument.load("hotels.xml"); function populatelist() {
        var hotels=oxmlDocument.selectNodes("/hotels/hotel");
        if (hotels != null) {
                d=document.forms["hotelupdate"].list;
                d.length=0;
                d[0]=new Option('--Please Select--','',true);
                for (i=0;i<hotels.length;i++) {
                        d.length++;
                        d[i+1]=new Option();
                        d[i+1].value=hotels[i].selectSingleNode("id").text;
                        d[i+1].text=hotels[i].selectSingleNode("name").text;
                }
        }
} function populatevalues() {
        d=document.forms["hotelupdate"];
// Get hotel ID #
        v=d.list[d.list.selectedIndex].value;
// Use this to read the hotel/phone node having this hotel ID
        field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/phone");
// Set form's phone field to the text of this node
        d.phone.value=field.text;
// Now to read the hotel/address node having this hotel ID
        field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/address");
// Set form's address field to the text of this node
        d.address.value=field.text;
} //--&gt; &lt;/script&gt; &lt;form name="hotelupdate" id="hotelupdate" action="post" method="http://www.my-server.com/myurl.php" onsubmit="alert('This would send these values to your website');return false;"&gt; &lt;select name="list" id="list" onchange="populatevalues()"&gt;&lt;/select&gt; Phone : &lt;input type="text" name="phone" id="phone" size="15" maxlength="24" /&gt; &lt;br /&gt; &lt;textarea name="address" id="address" rows="3" cols="40" wrap="virtual"&gt;&lt;/textarea&gt; &lt;br /&gt; &lt;input type="submit" name="submit" id="submit" value="Send !" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; At 13:25 20/11/2003 +0000, you wrote:
Date: Wed, 19 Nov 2003 20:02:43 +0000 To: php-db@lists.php.net From: Neil Smth <php@comatose.freeserve.co.uk> Cc: hhwee@towa.com.sg Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DB] Read file It's usually easier to show with an example : This took about 30 minutes to write : Here's an XML file - copy and paste, and save as hotels.xml :
<?xml version="1.0"?> <hotels>
        <hotel>
                <id>1</id>
                <name>Bangkok oriental</name>
                <address>50 High Street, Kowloon</address>
                <phone>+12 451 708 3282</phone>
        </hotel>
        <hotel>
                <id>2</id>
                <name>Hilton Marriott</name>
                <address>2042 Michael Wood Street</address>
                <phone>+44 238 9125467</phone>
        </hotel>
        <hotel>
                <id>3</id>
                <name>Swallow Royal</name>
                <address>91-97 Royal Fort Crescent</address>
                <phone>+01 1209 432 2345</phone>
        </hotel>
</hotels>

« previous php.db (#31666) next »