SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: generating XML

  1. #1
    SitePoint Member
    Join Date
    May 2004
    Location
    India
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    generating XML

    Hi,
    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 a <select> tag with relevant options is available. the relevant code

    Code:
    <form name="form1">
    <select name="sel" onchange="loadFile();">
    <option> Choose the map u prefer
    <option value="C:\My Documents\usa.jpg">US
    <option value="C:\My Documents\uk.jpg">UK
    <option value="C:\My Documents\spain.jpg">Spain
    <option value="C:\My Documents\greece.jpg">Greece
    </select>
    </form>
    now as soon as the user chooses one of the select options, that image is displayed on the page using the code:

    Code:
    function loadfile() {
    var fileName = document.form1.sel.value;
    if (fileName != "") {
    location.href = fileName;
    }

    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 a new 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:

    Code:
    <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
    for ur reference i am giving the code i have used to generate the XML as described above but on a single form:

    var sel_1 = document.form1.sel;
    var txt_1 = sel_1.options[sel_1.selectedIndex].text;
    var opt_1 = sel_1.options[sel_1.selectedIndex].value;
    var sel_2 = document.form1.sel2;
    var txt_2 = sel_2.options[sel_2.selectedIndex].text;
    var opt_2 = sel_2.options[sel_2.selectedIndex].value;
    var theStr = "<choice>\n";
    theStr += "<pic> " + opt_1 + " </pic>\n";
    theStr += "<tex> " + opt_2 + " </tex>\n";
    theStr += "</choice>";
    alert(theStr);

    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,

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...i am forced to take help from the forums.
    Well....that makes us feel all warm & fuzzy.

    Hmm - it's always a problem when someone says 'for [yo]ur reference...' in that it's usually critical to see exactly what they're up to. If your drop-downs are in different files, you'll need some mechanism to transfer the selected data to the 'main' document. The references to local files are confusing. What sort of environment will the final product be running in?
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    May 2004
    Location
    India
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    thank u for the quick reply. i am afraid i didn't understand what u meant by "what sort of environment the final product will be running in"?
    from what i can infer, my product will just be running on an ordinary browser (mostly IE, occasionally Netscape). the final output will be a simple alertbox displayed on the browser.
    regarding the reference to local file, what i want to acheive is: to generate XML (preferably using javascript). ie i want to have form based graphical interface that is available to the user. the user just clicks on the images and from the available options (the pre-specified files), selects his choice and finally the dynamic XML is displayed to the user showing the selections he has made.
    hope i have made things somewhat clear and waiting to hear from u.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •