Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

using javascript to create XML

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
consider a simple form (code given below):
<form name="form1">
<select name="sel">
<option label="1" value="C:\My Documents\a.jpg">US</option>
<option label="2" value=C:\My Documents\b.jpg">UK</option>
<option label="3" value=C:\My Documents\c.jpg">SA</option>
<option label="4" value=C:\My Documents\d.jpg">AUS</option>
</select>

<select name="sel2">
<option label="1" value="C:\My Documents\abc.txt">area1</option>
<option label="2" value=C:\My Documents\daf.txt">area2</option>
<option label="3" value=C:\My Documents\efg.txt">area3</option>
<option label="4" value=C:\My Documents\kjl.txt">area4</option>
</select>
</form>
<input type="button" value="submit">

now the user selects 'US' from the first <select> tag and 'area1' from the second <select> tag and clicks on the submit button.
now is it possible to write a javascript code that creates a XML file that encapsulates the two values chosen by the user. for example the XML code could be:

<choice>
<pic> 1 </pic>
<tex> 1 </tex>
</choice>
where '1' in the <pic> tag is the label id that represents the 'a.jpg' file and '1' in the <tex> tag is the label id that represents the 'abc.txt' file. if the user selcts another option, the relevant label should be stored in the XML file. ie if user selects 'SA', the <pic> tag should contain the value '3' which is the label for 'SA'
is it possible to implement such a functionality?? i am eager to hear ur comments on this.
thanks in advance
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First it is easy to format the code you want with using the values:


Now actually saving the xml is tricky!
look at this: http://www.devguru.com/Technologies/xmldom/quickref/document_save.html
Eric
 
Sri Sar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
thank you for ur prompt reply. i am going through the code and link u have mentioned. thanks once again.
 
Sri Sar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
i was working on the code u have given and need ur clarification s on a couple of points:
i just want to know what do "D1" and "D2" u have mentioned in the code
mean?? ie in "var sel_1 = document.FormName.D1", what does "D1" represent??
waiting to hear from u
 
Sri Sar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
i have found out what is D1 in the code. it is the name of the select tags.
i am currently working on saving the XML file and will contact u if necessary. thanks
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am afraid i need to trouble u again. since i am new to javascript programing i am forced to seek help.
in my main page say 'home', i have two images and a submit button.as soon as the first image is clicked, a new page, page1, opens in which the a 'select' tag with relevant options is available. the relevant code

now as soon as the user chooses one of the select options, that image is displayed on the page using the code:

after the image is displayed, the user clicks on a 'back' button that takes him back to 'home' page. here he clicks on the second image and the same procedure as above is repeated but with text files displayed on the resulting page, 'page2'. the user clicks on a 'back' button and returns to the 'home' page.
when he clicks on the 'submit' button on the 'home' page, a XML file that contains the two files he has chosen earlier is to be generated ie it is of the form:
<choice>
<pic>C:\My Documents\usa.jpg</pic>
<tex>C:\abc.txt</tex>
</choice>

this XML file is a dynamic one and the value of the <pic> and <tex> tags changes depending on the choice made by the user. this XML is to be generated only when the 'submit' button in the 'home' page is clicked
i have successfully used the code (provided by you in ur earlier reply), but now i need to generate the XML taking ouptut from a combination of pages.
the above functionality is a small part of an application i am developing and since i was stuck in this code for the last few days, i am forced to take help from the forums.
thanks in advance
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic