Click to See Complete Forum and Search --> : Filling in a form with data from an XML file


pcvodak
01-10-2008, 11:50 AM
I'm trying to use data from an XML file to fill in several values of an HTML form that when the submit button is click will add an item to a shopping cart.

Here is a snippet of the form code:

<form target="cart" action="url goes here" method="post">
<input type="image" src="button.gif" border="0" name="submit" alt="submit">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="BOGUS COMPANY">
<input type="hidden" name="item_name" value=<%ITEM NAME%>>
<input type="hidden" name="item_number" value=<%ITEM NUMBER%>>
<input type="hidden" name="amount" value=<%PRICE%>>
</form>

Here is the XML file info:

<PRODUCTS>
<ITEMS>
<ITEM NAME>Toy Car</ITEM NAME>
<ITEM NUMBER>TC101</ITEM NUMBER>
<PRICE>15.00</PRICE>
</ITEMS>
</PRODUCTS>

I have several items in the XML file and several items will be displayed on the HTML page with each item having it's own submit/add to cart button.

I can't seem to get this to work. Any help would be appreciated.

dj_segfault
01-10-2008, 12:59 PM
Are you trying to do this on the client side or the server side? If you're doing it on the server side, that depends on what technologies you're using there.

If you're doing it on the client side, one way to do it is to have the page make a JavaScript AJAX call that gets the XML file, parses it, and sets the values of the elements in the form. Call it from your body onload= function.

Another way to do it, though, would be to have the AJAX call get the entire HTML for the form, and set the contents of a div tag to what the AJAX call gets. It all depends if you would rather have more control on the client side or the server side.

Of course you didn't say what you tried, only that it didn't work, so you may have already tried this. the more information you post, the easier it is to help you.

pcvodak
01-14-2008, 09:25 AM
After looking at this problem for a while I tried a different way, I'm using a table to load the information in to and I have the form inside the table and I'm able to replace the value with the datfld from the XML file.