1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to save data from dropdownlist to XM fileL by JavaScript

Discussion in 'JavaScript' started by natzjordaan, Jan 6, 2012.

  1. #1
    Hey guys

    I export data from Javascript to Xml file. I have tried several ways to break a line in xml file like document.write("<br/>"); or document.writeln(); etc, but seem it is impossible.

    Maybe you can give me a solution......

    Look at below:

    XML File:

    <?xml version="1.0"?>
    <DATA>
    <Cust><Select>Debit Card</Select></Cust><Cust><User>Jan</User></Cust><DATA>

    I want to break <Cust> from another <Cust>.

    Javascript:

    function ok_click() {
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
    xmlDoc.async = false;
    xmlDoc.load("data.xml");
    if (xmlDoc.readyState == 4 && xmlDoc.parseError.errorCode == 0) {
    var root = xmlDoc.documentElement;

    var e1 = document.getElementById("Select1");
    var _account_type = xmlDoc.createTextNode(e1.options[e1.selectedIndex].value);

    var e2 = document.getElementById("Select2");
    var _user = xmlDoc.createTextNode(e2.options[e2.selectedIndex].value);


    var account_type = xmlDoc.createNode(1, "Select", "");
    var user = xmlDoc.createNode(1, "User", "");


    account_type.appendChild(_account_type);
    user.appendChild(_user);


    var cust = xmlDoc.createNode(1, "Cust", "");

    cust.appendChild(account_type);
    document.write("<br/>");
    cust.appendChild(user);


    root.appendChild(cust);

    SaveXML(xmlDoc, "data.xml");
    alert("Save!");
    }
    }

    Your help would much appreciated [​IMG]

    Thanks
    Natz
     
    natzjordaan, Jan 6, 2012 IP
  2. natzjordaan

    natzjordaan Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    oh yes have a look at SAVE function as well:

    function SaveXML(xmlDoc, filename) {
    var outputXML = new String(xmlDoc.xml);
    var mfObj = new ActiveXObject("Scripting.FileSystemObject");
    var absPath = getPath();
    var file = mfObj.CreateTextFile(absPath + filename, true);
    file.Write(outputXML);
    file.Close();
    }

    function getPath() {
    var path = document.location;
    var str = new String(path);
    var end = str.lastIndexOf("/");
    var absolutePath = str.substring(8, end) + "/";
    absolutePath = absolutePath.replace(/%20/g, " ");
    return absolutePath;
    }
     
    natzjordaan, Jan 6, 2012 IP