DenKain
05-03-2006, 11:34 PM
Okay I'm at work so thats why I have not searched through the forum so I hope you don't go to hard on me (I know I usually flame people for that). Anyway what I am trying to do is enter data into a set of text boxes and have that info ran through a function in javascript. I made a simple demo just to see if I could even do this and have so far failed. I was hoping someone could help.
Thanks in advanced,
DenKain
<html>
<head>
<script language="JavaScript">
function dude()
{
theText = my;
alert(theText);
}
</script>
</head>
<body>
<form>
<input ="text" name="my">
<input type ="submit" Value ="Submit" onclick="dude()">
</form>
</body>
</html>
Bill Posters
05-03-2006, 11:54 PM
function dude()
{
theText = document.forms[0].my.value;
alert(theText);
}
...
<form>
<input="text" name="my">
<input type="button" value="Submit" onclick="dude()">
</form>
(Incidentally, I changed the input button from a submit button to a generic button in order to prevent it submitting in this demo.)
_Aerospace_Eng_
05-03-2006, 11:57 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function dude()
{
//this gets the value, forms[0] represents the first form on the page
theText = document.forms[0].my.value;
//you can also use document.getElementById(), the input needs to have id="..."
theTextById = document.getElementById('my').value;
alert("This uses the name of the input: " + theText);
alert("This uses the id of the input: " + theTextById);
//this prevents the form from actually being submitted but still allowing use to hit enter or submit
return false;
}
</script>
</head>
<body>
<!--since the dude() function returns something we need to return that value to the form-->
<form action="#" onSubmit="return dude()">
<input type="text" name="my" id="my">
<input type="submit" value="Submit">
</form>
</body>
</html>
Bill beat me to it
Codes are similar but a bit different I prefer the submit button just because users can still hit the enter key or submit button.
DenKain
05-04-2006, 12:47 AM
Thank you so much that worked great. The thing is I applied that to the actual script I was making and it is having a separate issue. As you may notice when you run it the function starts even when it is not called to. Any ideas??
<html>
<head>
<script language="JavaScript">
function theDate()
{
myMonth = document.forms[0].month.value;
myDay = document.forms[0].day.value;
myYear = document.forms[0].year.value;
MyDate = myMonth+"/"+myDay+"/"+myYear;
//TargetDate = "5/3/2006 11:00 PM";
TragetDate = "'MyDate' + 11:00 PM"; //yes thats pseduo code for the moment
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
}
</script>
<script language="JavaScript" src="http://www.mythicsoftware.com/work/countdown.js"></script>
</head>
<body>
<form action="#" onSubmit="return theDate">
Month:
<input ="text" size = "2" name="month">
<br>
Day:
<input ="text" size = "2" name="day">
<br>
Year:
<input ="text" size = "4" name="year">
<br>
<input type ="submit" Value ="Submit">
</form>
<script language="JavaScript">
myMonth = document.forms[0].month.value;
myDay = document.forms[0].day.value;
myYear = document.forms[0].year.value;
MyDate = myMonth+"/"+myDay+"/"+myYear;
//TargetDate = "5/3/2006 11:00 PM";
TragetDate = MyDate;
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.mythicsoftware.com/work/countdown.js"></script>
</body>
</html>
felgall
05-05-2006, 06:59 AM
onSubmit="return theDate"
should be
onSubmit="return theDate()"
DenKain
05-10-2006, 09:10 PM
Here is what I was trying to do....still can't get the time to work though.
inputs.php
<HTML>
<FORM action="countdown.php" method="POST">
Enter Month: <INPUT type="text" name="month"><BR>
Enter Day:<INPUT type="text" name="day"><BR>
Enter Year:<INPUT type="text" name="year"><BR>
<INPUT type="submit" name="submit" value="Submit">
</FORM>
</HTML>
countdown.php
<html>
<head>
</head>
<body>
<script language="JavaScript">
TargetDate =
<?PHP
echo CHR(34) . $_POST["month"] . CHR(47) . CHR(34) . CHR(43);
echo CHR(34) . $_POST["day"] . CHR(47) . CHR(34) . CHR(43);
echo CHR(34) . $_POST["year"] . CHR(34) . CHR(43);
?> " 10:30 PM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
DisplayFormat = "%%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.mythicsoftware.com/work/countdown.js"></script>
</body>
</html>