-
DTHML Question
This may be a dumb question, but how do you allow a user to change the content on a page?
I have a page that uses data from a cookie. I want the user to be able to edit the cookie-based data if necessary, but I don't want to have to reload the ASP page (fewer DB calls, etc.), just change the text on the page that was originally created from the cookie.
-
Depending on the browser the page can be changed through JavaScript...If you got a little more specific it would make things a bit clearer to see what you mean.
-
Even though this doesn't use cookies, I think this I can take it from there. Say I had something like this:
<HTML>
<SCRIPT language="javascript">
function WrtieNewStuff()
{
write some new text
}
</SCRIPT>
<BODY>
The old stuff. <a href='javascript:WriteNewStuff();'>Click to write new stuff</a>
</body>
</HTML>
When the user clicked the link, the link would call the WriteNewStuff function and write some text or HTML. How do I preserve what is already on the page (ie "The old stuff") where the page reads "The old stuff. The new stuff".
-
the only way to preserve it is if it was being loaded from the database. or write another cookie to preserve it.
-
You can store the old text in a variable:
Code:
...
<script LANGUAGE = "JavaScript">
var oldStuff;
function writeNewText(strNewText){
oldStuff = document.all.varText.innerText;
document.all.varText.innerText = strNewText;
alert(oldStuff + ' ' + '\nWas saved!');
}
</script>
...
<p ID = "varText">This text is old</p>
...
<a HREF = "JavaScript:writeNewText('This text is new');">Write new text</a>
-
Of course, once the variable goes out of scope, you lose any saved values. To persist the values you'd have to use cookies or a db.
-
Exactly what I was looking for. Thanks.