alvinchua Posted May 9, 2007 Share Posted May 9, 2007 hi ppl erm.. this javascript is to generate current date ... <script type="text/javascript"> <!-- var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() document.write(month + "/" + day + "/" + year) //--> </script> and this is the code for a combobox... <SELECT name = "select" id ="select"> <OPTION>i need the current date to be display !! <OPTION>USA <OPTION>UK <OPTION>omg </SELECT> how can i insert the current date generated to the combo box ??? Link to comment https://forums.phpfreaks.com/topic/50667-insert-the-current-date-generated-to-the-combo-box/ Share on other sites More sharing options...
per1os Posted May 9, 2007 Share Posted May 9, 2007 Maybe by posting this into a JavaScript forum? Link to comment https://forums.phpfreaks.com/topic/50667-insert-the-current-date-generated-to-the-combo-box/#findComment-249058 Share on other sites More sharing options...
Psycho Posted May 9, 2007 Share Posted May 9, 2007 You should start by using good coding: - Don't use select as the id name - Always use closing tags (options) - Give your options values - otherwise what's the point <script type="text/javascript"> <!-- var currentTime = new Date(); var month = currentTime.getMonth() + 1; var day = currentTime.getDate(); var year = currentTime.getFullYear(); var today = month + "/" + day + "/" + year; //--> </script> <SELECT name = "select" id ="selectField"> <script type="text/javascript"> <!-- document.write('<OPTION value="'+today+'">'+today+'</option>'); //--> </script> <OPTION value="USA">USA</option> <OPTION value="UK">UK</option> <OPTION value="omg">omg</option> </SELECT> Link to comment https://forums.phpfreaks.com/topic/50667-insert-the-current-date-generated-to-the-combo-box/#findComment-249077 Share on other sites More sharing options...
alvinchua Posted May 12, 2007 Author Share Posted May 12, 2007 hmm i need it to be displayed in the combo box .... and the value is passed to a form ... something like below... and later on will be added to the database .. <?php if(!isset($_POST['button'])) { ?> <form method="post" name="tryform" id="tryform"> <SELECT name = "select" id ="select"> <OPTION>India <OPTION>USA <OPTION>UK <OPTION>omg </SELECT> <input name="button" type="submit" id="button" value="SUBMIT"> </body> <?php } ?> </html> i just need the time generated to be passed to a form and later on can be added into the database Link to comment https://forums.phpfreaks.com/topic/50667-insert-the-current-date-generated-to-the-combo-box/#findComment-251638 Share on other sites More sharing options...
AndyB Posted May 12, 2007 Share Posted May 12, 2007 If you want php to generate today's date, use $today = date("Y-m-d") to generate a nice, usable, date format. Link to comment https://forums.phpfreaks.com/topic/50667-insert-the-current-date-generated-to-the-combo-box/#findComment-251652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.