jQuery get value of input datetime-local

jQuery get value of input datetime-local



I need to get the value from input datetime-local, but the variable is empty, whereas everything is ok with text inputs. Here is code:


<script>
var datetimeval = $("#datetime").val();
var textval = $("#text").val();
</script>
<input id='text' type='text' />
<input id='datetime' type='datetime-local' />



Could you tell me please, how to fix it?





you need to add the script after adding the input elements
– Arun P Johny
Aug 18 '14 at 13:33





Have you debugged your code? What errors do you get?
– j08691
Aug 18 '14 at 13:35





you wrap the code inside document.ready learn.jquery.com/using-jquery-core/document-ready
– Balachandran
Aug 18 '14 at 13:37






I cannot get the datetime even so: jsfiddle.net/t89q3cfc/3
– egorfadeev
Aug 18 '14 at 14:01




2 Answers
2



Try this


<input id='text' type='text' value="test"/>
<input id='datetime' type='datetime-local' />
<script>
var datetimeval = $("#datetime").val();
var textval = $("#text").val();
alert(textval);
alert(datetimeval);
</script>



Demo: Fiddle



Note: I gave default value to text input textbox





Thanks for reply. But I cannot get the datetime even so: jsfiddle.net/t89q3cfc/3
– egorfadeev
Aug 18 '14 at 14:01





@egorfadeev: you want to get current date time in textbox or the value of textbox that user has entered?
– Sid M
Aug 18 '14 at 14:05






I need to get the value from <input id='datetime' type='datetime-local' /> when I click on button
– egorfadeev
Aug 18 '14 at 14:10






@egorfadeev : then what's the problem i get the value of your textbox after i enter both date and time.
– Sid M
Aug 18 '14 at 14:23



You should set its value of all parts, including y-m-d h:m, especially "h:m". It's ok for my case.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

Node.js puppeteer - Use values from array in a loop to cycle through pages