0

Using jquery mobile 1.3 I was able to collect and display values from some input fields using localSotorage with this function:

    <script type="text/javascript">
    function datosCliente (info) {
        localStorage.setItem(info.name,info.value);
    }
</script>

And here is a sample of one input field calling the function:

<label for="basic">Nombre:</label>
        <input type="text" name="nombre" id="basic" data-mini="true" onkeyup="datosCliente(nombre)"/>

I was hoping to do the same on an input type date:

<label for="fecha">Fecha</label>
        <input name="fecha" id="fecha" type="date" data-role="datebox" data-options='{"mode":"calbox", "useNewStyle":true}' onkeyup="datosCliente(fecha)" />

And the display the value using:

<p><span>Fecha: </span><script>document.write(localStorage.getItem("fecha"));</script></p>

But is it turns out All I get is null when I want to display the value of this field. Is it because I am using the jQueryMobile - DateBox plugin to pick the date ? Or I have to try a different approach to collect the value from this type of input ?

Paul
  • 2,186
  • 20
  • 26
user2109326
  • 103
  • 2
  • 11
  • How are you saving the date in localStorage? Note than localStorage can only store strings. So if you are giving it an object of type `Date()`, it will store it as a string. – dlock Mar 05 '13 at 02:37

2 Answers2

1

It would be a good idea to use onchange rather than onkeyup, especially since the browser UI won't trigger keypresses.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

Not sure if this is an answer per-say, but you can try changing nombre and fecha to this. And might I add, instead of using document.write, you could use console.log, that way you can tell if it is an object as opposed to a string, etc. This would probably have gone in the comments section but I don't seem to have the privileges to do that just yet. Good luck.

Community
  • 1
  • 1
slattman
  • 98
  • 6