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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update button to update file on webpage

Status
Not open for further replies.

jy3

Programmer
Aug 20, 2003
6
IE
HI,
I have a list of commands on a help page and new commands are constantly added. I want to put in a delete button so you can remove this file from the list..any ideas??
 
Not sure what you mean, but it sounds like you want JavaScript to write/update a file - which it cannot do. Consider using a server-side technology: ASP, PHP, Perl, ColdFusion, JSP, etc...

Adam
 
So basically, simple content management, from a web interface?

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
I am using ASP.
This is the page that goes on to open my list of server commands..(used a bit of VB script here too)
<% @LANGUAGE=&quot;VBSCRIPT&quot; %>
<%



'*** create fso object
dim objFSO
set objFSO = createobject(&quot;scripting.filesystemobject&quot;)

'***----
'*** define the location of your homepage from here
'*** this will be used after updating or cancelling
dim stHomePage
strHomePage = &quot;Template.html&quot;

Dim commandFile
commandFile = &quot;server_config.asp&quot;
'***---
'*** get the name of this page (script) dynamically - you could specify this if you want
dim strScriptName
strScriptName = request.servervariables(&quot;script_name&quot;)
strScriptName = mid(strScriptName, instrrev(strScriptName, &quot;/&quot;) + 1 )
'***---


'***--- if they've not submitted the Save form
if request.form(&quot;Save&quot;) = &quot;&quot; then

Dim Regex, title
Set Regex=New RegExp
Regex.Global = True
Regex.IgnoreCase = False
Regex.Multiline = True
Regex.Pattern=&quot;(EXAMPLE*|Example|DESCRIPTION|SYNOPSIS|OPTIONS|#\d+|\$\s+\w*\s\w*)&quot;

dim strFileContents
strFileContents = Regex.Replace(Request.form(&quot;Tfile&quot;),&quot;<font COLOR='#8448FF'><b>$1</b></font>&quot;)
strFileContents = Replace(strFileContents, vbCrLf, &quot;<BR>&quot;)

title = Request.Form(&quot;title&quot;)

'***---- if they're updating....
else if request.form(&quot;Save&quot;) <> &quot;&quot; then

'*** get the contents
dim strWriteContents
strWriteContents = request.form(&quot;pageHTML&quot;)



























'*** page text isn't a requirement as we can sort out an error message to some extent in replace.
if strWriteContents = &quot;&quot; then
strWriteContents = &quot;This page is currently un-available.&quot;
strWriteContents = strNewContent & vbCrLf & &quot;<br><br>&quot;
strWriteContents = strNewContent & vbCrLf & &quot;We apologise for any inconvenience caused.&quot;
end if

Dim objMenuPage, i
objFile = Request.form(&quot;fileName&quot;)
if(objFSO.FileExists(Server.MapPath(objFile) ) )Then
strFileContents = strWriteContents
error = &quot;The file &quot;& objFile &&quot; already exists. please specify a different file name&quot;
else
Const ForReading = 1, ForWriting = 2, ForAppending = 8


strPath = Request.form(&quot;path&quot;)
strFullName = objFSO.BuildPath(strPath, objFile)
Set objMenuPage = objFSO.CreateTextFile(strFullName, forWriting, False)


'write the HTML page
objMenuPage.WriteLine&quot;<html><head><title>&quot; & Request.Form(&quot;pageTitle&quot;)& &quot;</title></head><body>&quot;
objMenuPage.WriteLine strWriteContents
objMenuPage.WriteLine &quot;</body></html>&quot;
objMenuPage.Close

'Add the link to the command file
Dim f,ts
set f = objFSO.GetFile(Server.MapPath(commandFile))
set ts = f.OpenAsTextStream(ForAppending, -2)

'Write the link and specify how you want it to look. All &quot;&quot; in ther html code must be changed to ''
ts.write(&quot;<font size='3'><a href ='&quot; & objFile &&quot;'>&quot; & objFile & &quot;</a></font><br>&quot;)

Response.Redirect(commandFile)



end if
end if

End if
%>
<html>
<head>
<title>Text Editor</title>
<script language=&quot;javascript&quot;>
<!--
function over(element) {
element.style.borderStyle= &quot;solid&quot;;
element.style.borderWidth = &quot;1px&quot;;
element.style.borderColor = &quot;#000000&quot;;
element.style.backgroundColor = &quot;#F1F1F1&quot;;
element.style.cursor = &quot;hand&quot;;
}

function out(element) {
element.style.borderColor = &quot;#ccccff&quot;;
element.style.backgroundColor = &quot;#ccccff&quot;
element.style.cursor = &quot;default&quot;;
}

function readyDiv() {
var theHTML;
theHTML = document.all.tags('div')['pageHTML'].innerText;
document.all.tags('div')['pageHTML'].innerHTML = theHTML;
}

function cmdExec(cmd,opt) {
pageHTML.document.execCommand(cmd,&quot;&quot;,opt);
document.body.all.tags('div')['pageHTML'].focus();
}

function createLink() {
cmdExec(&quot;CreateLink&quot;);
}

function insertImage() {
var sImgSrc = prompt(&quot;Image: &quot;, &quot;[domain].[ext]/[folder]/[file]&quot;);
if(sImgSrc!=null)
cmdExec(&quot;InsertImage&quot;,sImgSrc);
}

function div2hidden(objForm) {
tmpStr = objForm.fileName.value
if(tmpStr == &quot;&quot;)
{ alert(&quot;Please specify a file name!!&quot;);
document.frmedit.fileName.focus();
return false;
}

str= String(&quot;.html&quot;);
if(tmpStr.substring(tmpStr.length - 5,tmpStr.length) != str)
{ alert(&quot;Please save file as type .html&quot;);
document.frmedit.fileName.focus();
return false;
}
objForm.pageHTML.value = document.all.tags('div')['pageHTML'].innerHTML;
return true;
}

function go(where) {
window.location.href = where;
}
//-->
</script>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<form name=&quot;frmedit&quot; method=&quot;post&quot; onsubmit=&quot;return div2hidden(this);&quot; action=&quot;editor.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;pageHTML&quot; value=&quot;&quot;>
<input type=&quot;hidden&quot; name=&quot;Save&quot; value=&quot;1&quot;>
<input type=&quot;hidden&quot; name=&quot;pageTitle&quot; value=&quot;<%= title%>&quot;>
<input type=&quot;hidden&quot; name=&quot;path&quot; value=&quot;D:\Inetpub\<input type=&quot;hidden&quot; name=&quot;file&quot; value=&quot;<%= objFile %>&quot;>
<table width=&quot;550&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; align=&quot;center&quot; style=&quot;border-style: solid; border-width: 1px; border-color: #000000;&quot; bgcolor=&quot;#ccccff&quot;>
<tr>
<td width=&quot;100%&quot; align=&quot;center&quot;>
<input type=&quot;submit&quot; value=&quot;Save&quot;> &nbsp;
<input type=&quot;button&quot; value=&quot;Cancel&quot; onclick=&quot;go('<%= strHomePage %>');&quot;>
</td>
</tr>
<tr>
<td>
<table width=&quot;100%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;1&quot; bordercolor=&quot;#ccccff&quot;>
<tr>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('cut')&quot;>
<img src=&quot;img/cut.gif&quot; alt=&quot;CUT - Ctrl + X&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('copy')&quot;>
<img src=&quot;img/copy.gif&quot; alt=&quot;COPY - Ctrl + C&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('paste')&quot;>
<img src=&quot;img/paste.gif&quot; alt=&quot;PASTE - Ctrl + V&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('bold')&quot;>
<img src=&quot;img/bold.gif&quot; alt=&quot;BOLD - Ctrl + B&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('italic')&quot;>
<img src=&quot;img/italic.gif&quot; alt=&quot;ITALIC - Ctrl + I&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('underline')&quot;>
<img src=&quot;img/underline.gif&quot; alt=&quot;UNDERLINE - Ctrl + U&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('justifyleft')&quot;>
<img src=&quot;img/left.gif&quot; alt=&quot;Justify Left&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('justifycenter')&quot;>
<img src=&quot;img/center.gif&quot; alt=&quot;Center&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('justifyright')&quot;>
<img src=&quot;img/right.gif&quot; alt=&quot;Justify Right&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('insertorderedlist')&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; src=&quot;img/numlist.gif&quot; alt=&quot;Ordered List&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('insertunorderedlist')&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; src=&quot;img/bullist.gif&quot; alt=&quot;Unordered List&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('outdent')&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; src=&quot;img/unindent.gif&quot; alt=&quot;Decrease Indent&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('indent')&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; src=&quot;img/indent.gif&quot; alt=&quot;Increase Indent&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;cmdExec('createLink')&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; src=&quot;img/link.gif&quot; alt=&quot;LINK - Ctrl + K&quot;>
</div>
</td>
<td valign=&quot;center&quot; align=&quot;center&quot; onmouseover=&quot;over(this);&quot; onmouseout=&quot;out(this);&quot; width=&quot;20&quot; height=&quot;20&quot;>
<div onclick=&quot;insertImage()&quot;>
<img hspace=&quot;2&quot; vspace=&quot;1&quot; align=&quot;absmiddle&quot; src=&quot;img/image.gif&quot; alt=&quot;Image&quot;>
</div>
</td>
</tr>
<tr valign=&quot;middle&quot;>
<td colspan=&quot;16&quot; width=&quot;100%&quot;>
<select onchange=&quot;cmdExec('foreColor',this[this.selectedIndex].value);this.selectedIndex=0&quot;>
<option value=&quot;0&quot;>Font Color</option>
<option value=&quot;#000000&quot;>Black</option>
<option value=&quot;#FF0000&quot;>Red</option>
<option value=&quot;blue&quot;>Blue</option>
</select>
&nbsp;
<select onchange=&quot;cmdExec('fontname',this[this.selectedIndex].value);&quot;>
<option selected>Font</option>
<option value=&quot;Arial&quot;>Arial</option>
<option value=&quot;Times New Roman&quot;>Times New Roman</option>
<option value=&quot;Verdana&quot;>Verdana</option>
</select>
&nbsp;
<select onchange=&quot;cmdExec('fontsize',this[this.selectedIndex].value);&quot;>
<option selected>Size</option>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
<option value=&quot;6&quot;>6</option>
<option value=&quot;7&quot;>7</option>
<option value=&quot;8&quot;>8</option>
</select>
</td>
</tr>
</table>
</td>
</tr>

<tr><td align =&quot;center&quot;><font color=&quot;red&quot; size=&quot;5&quot;><B><%=error%></B></font></td></tr>


<tr><td>Save file as...(e.g. command_name.html)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=&quot;text&quot; name=&quot;fileName&quot; size=&quot;60&quot; value= &quot;<%=title &&quot;.html&quot;%>&quot;></td></tr>
<tr>
<td align=&quot;left&quot;>
<!-- page content div -->






<div contentEditable=&quot;true&quot; id=&quot;pageHTML&quot; name=&quot;pageHTML&quot; style=&quot;border-style: solid; border-width: 1px; border-color: #000000; background-color: #FFFFFF; padding-left: 3px; padding-right: 3px; padding-top: 3px; padding-bottom: 3px; width: 750px; height: 380px;&quot;>





<%= strFileContents %>
</div>
<!-- / p c d -->
</td>
</tr>

<tr><td align =&quot;center&quot;><font color = &quot;red&quot; size=&quot;5&quot;><B><%=error%></B></font></td></tr>
<tr>
<td width=&quot;100%&quot; align=&quot;center&quot;>
<input type=&quot;submit&quot; value=&quot;Save&quot;> &nbsp;
<input type=&quot;button&quot; value=&quot;Cancel&quot; onclick=&quot;go('<%= strHomePage %>');&quot;>
</td>
</tr>
</table>

</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top