using HTML5 localStorage in forms?

65 views
Skip to first unread message

skye riquelme

unread,
Nov 21, 2012, 3:43:15 PM11/21/12
to TiddlyWiki
Hi All

I have been using localStorage extensively in my TW work, but cant
seem to get access to the data from within html forms....for
eample...why doesnt this simple bit of code set the localStorage item
"test"?? (the wikify at the end is just to check if test got set.)

<script>
function testResults (form) {
var TestVar = form.inputbox.value;
var test=localStorage.setItem("test",TestVar);
}
</script>
<html>
<form name="myform" action="" method="GET">Enter something in the box:
<BR>
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Click"
onClick="testResults(this.form)">
</FORM>
</html>
<<wikify {{localStorage.getItem("test")}}>>

Thanks in Advance
Skye

tiziano de togni

unread,
Nov 21, 2012, 4:20:18 PM11/21/12
to tiddl...@googlegroups.com
Il 21/11/2012 21:43, skye riquelme ha scritto:
> Hi All
>
> I have been using localStorage extensively in my TW work, but cant
> seem to get access to the data from within html forms....for
> eample...why doesnt this simple bit of code set the localStorage item
> "test"?? (the wikify at the end is just to check if test got set.)
>

Try this snippet, it should work:

<html>
<form name="myform" action="" method="GET">Enter something in the box:
<BR>
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Click"
onClick="testResults(this.form)">
</form>
</html><script>
testResults= function(form) {
var TestVar = form.inputbox.value;
var test=localStorage.setItem("test",TestVar);

wikify("localStorage key test = "+
localStorage.getItem("test")+"\n",place );
}
</script>



regards
--
tiziano de togni
______________________________________
http://tizziano.altervista.org/

skye riquelme

unread,
Nov 22, 2012, 6:52:03 AM11/22/12
to tiddl...@googlegroups.com
Thanks Tiziano....that worked.....
Reply all
Reply to author
Forward
0 new messages