Click to See Complete Forum and Search --> : Passing field data


Aronya1
09-09-2003, 11:34 PM
I think this will be easy to answer for someone who understands.

I am working on a form. One of the data fields I want to pass to the database is a date field. I have located a script that works fine to display the date on the web page, but I'm not sure it's placed correctly in my html code. Could someone please verify this for me? I just want to be sure the data will be included in the field when the form is processed, and I don't have the cgi script yet to test it with.

Here's the relevant portion of the form code:

<td width="84%"><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;
<input name="date" type="hidden" id="date"><SCRIPT LANGUAGE="Javascript"><!--

var aceDate=new Date()
var aceYear=aceDate.getYear()
if (aceYear < 1000)
aceYear+=1900
var aceDay=aceDate.getDay()
var aceMonth=aceDate.getMonth()+1
if (aceMonth<10)
aceMonth="0"+aceMonth
var aceDayMonth=aceDate.getDate()
if (aceDayMonth<10)
aceDayMonth="0"+aceDayMonth
document.write("<font color='000000' face='Arial' size='2'><b>"+aceMonth+"/"+aceDayMonth+"/"+aceYear+"</b></font></small>")

//--></SCRIPT>
</font></td>

So, do I have the javascript inserted in the proper place? Also, the field was originally intended to be hidden, but the date is displaying on the web page. This is not a problem, but it makes me question whether or not I'm doing this right.

Thanks in advance,
Aronya1

simpson97
09-10-2003, 02:14 AM
Try this , it works.

<html>
<head>
<SCRIPT LANGUAGE="Javascript">
<!--
function get_date() {
var aceDate=new Date()
var aceYear=aceDate.getYear()
if (aceYear < 1000)
aceYear+=1900
var aceDay=aceDate.getDay()
var aceMonth=aceDate.getMonth()+1
if (aceMonth<10)
aceMonth="0"+aceMonth
var aceDayMonth=aceDate.getDate()
if (aceDayMonth<10)
aceDayMonth="0"+aceDayMonth

// following line sets your hidden form field - I set it to text
// for demo purposes

document.form0.date.value = aceMonth+"/"+aceDayMonth+"/"+aceYear
}

window.onload = get_date

//-->
</SCRIPT>
</head>
<body>

<form name=form0>
<table>
<tr>
<td width="84%"><font size="2" face="Arial, Helvetica, sans-serif">

<!-- set following line back to hidden -->

<input name="date" type="text" id="date">

</td>
</tr>
</table>
</form>
</body>
</html>

Bob
simpson_97@yahoo.com

Aronya1
09-10-2003, 12:14 PM
Bob,

Thanks for the reply, but your code seems to be doing the same thing mine does. Maybe I'm not being clear enough in what I'm asking...


Here's the code for my data field:
<input name="date" type="hidden" id="date"> If my js code is inserted here, is the date going to be passed to my database?

As I'm looking at all of this, I think I've worked out the answer to my own question: Whatever is between the <td> & </td> tags will be passed to the database, hidden field or not, right? I'm really just looking for confirmation that I've got things set up correctly.

Aronya1

simpson97
09-10-2003, 01:00 PM
Yes just set input field to hidden & it will be passed in post.
I set it to text for test purposes.

Bob

Aronya1
09-10-2003, 06:48 PM
Thanks for the help. I'll sleep better now. :p