Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving data to a xml file

Status
Not open for further replies.

alcool9999

Technical User
Apr 1, 2008
3
GB
Hi i have a script that has a text area with a form in it.
when the user clicks submit it saves the data to an xml file so i can see the data.

when you do it again it overites the data.
is there anyway i can stop this.

code:
<HTA:APPLICATION ID="oWriteXML"
APPLICATIONNAME="Save Text to XML"
VERSION="1.0"
CAPTION="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="maximize">

<title>Write text and save to XML document</title>
<script language="JScript">
<!--

function saveXML(saveWhat, saveWhere)
{
document.getElementById('gen').innerHTML='Generating File...';

var fileSys = new ActiveXObject("Scripting.FileSystemObject");
var xmlFile=fileSys.CreateTextFile(saveWhere);

var allXML='';
allXML+=document.getElementById('formatPart1').innerHTML;
allXML+=saveWhat.value;
allXML+=document.getElementById('formatPart2').innerHTML;

xmlFile.write(allXML);
xmlFile.close();

document.getElementById('gen').innerHTML='Done. You may now close this window or view what you submitted.';
}

//-->
</script>
</head>

<body>

<!-- This is how the text will be formatted in the XML file. Part 1 is what will
be generated before the text, while part 2 will be generated after the text.
The XMP tag does not eliminate whitespace like other tags do. -->


<xmp id="formatPart1" style="display:none;">
<?xml version="1.0"?>
<note>
<text>
</xmp>

<xmp id="formatPart2" style="display:none;">
</text>
</note>
</xmp>

<textarea name="text" id="text" rows="5" cols="40">
Name:
Email:
Favourite Animal:

Favourite Sport:
</textarea><br />
<input type="button" value="Submit" onclick="saveXML(document.getElementById('text'), 'text.hta');" /><br />
<span id="gen"></span>



Thankyou
 
[1]
>when you do it again it overites the data.
>is there anyway i can stop this.
If you want to let user save only once, you can do the following.

><input type="button" value="Submit" onclick="saveXML(document.getElementById('text'), 'text.hta');" /><br />
[tt]<input type="button" value="Submit" onclick="saveXML(document.getElementById('text'), 'text.hta');[red]this.disabled=true;[/red]" /><br />[/tt]

If the users have good reason to revise the input, they no choice but to reload the hta.

[2] A couple of things you need to re-think.

[2.1] The structure of xmp containing note, text look really anti-climax. If those are the fixed parts, you should simply put them as string in the function, not in the marked up body of the hta.

[2.2] It is an unsatisfactory markup with input elements (text, textarea, button...) without a form element. They should better be wrapped within a form element, though it may not be having any operational consequence in this hta.
 
Thank you
i have actually write a better script now that does exactly what i want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top