View Full Version : sent input of a prompt

07-28-2002, 08:20 PM
See this script (found it on this site)

<script language="JavaScript">
var name=prompt("Enter Your Name, Please.","name");
var today = new Date ()
var hrs = today.getHours();
document.writeln("<b><font size=4 face='Comic Sans MS'>");
if (hrs <= 12)
document.write("Good Morning "+name+'!');
else if (hrs <= 18)
document.write("Good Afternoon "+name+'!');
document.write("Good Evening "+name+'!'); document.writeln("<br>");
// -->

How can i sent the input of the prompt as an input form? I want to use a prompt(1) as a question, followed by a prompt(2). Then i want to print the input of the prompts (document.write) and finaly sent the input by a post action. But how can i sent the inpyut of the prompts?

07-29-2002, 05:39 AM

<form action="javascript:alert('Submitted.')" method="post">
<input type="hidden" name="user_name" value="">
<script type="text/javascript" language="javascript">

var name = prompt('Enter Your Name, Please.', 'name');
if (name) {
name = name.charAt(0).toUpperCase() + name.substring(1); //capitalize?
var today = new Date();
var hrs = today.getHours();
document.write('<b><font size="5" face="Comic Sans MS">');
if (hrs <= 12) document.write('Good Morning, ');
else if (hrs <= 18) document.write('Good Afternoon, ');
else document.write('Good Evening, ');
document.write('<font color="darkred">' + name + '</font> !</font></b>');
document.forms[0].user_name.value = name;
setTimeout('document.forms[0].submit()',3000); //3 sec. delay


07-29-2002, 02:47 PM
Just use a hidden field and change the value dynamically to the value of the prompt.

Hope that helps!

Happy coding! :)