[thelist] Using JS to change hidden date value in Netscape?

Josué Figueira Machado jmachado at mindspring.com
Fri Feb 15 20:27:00 CST 2002


Bob,

I put your code in a function that gets called onsubmit. Something like this:

<script type="text/javascript">
function getDate(){
   today=new Date();
   day=today.getDate().toString();
   jsmonth=today.getMonth();
   jsyear=today.getFullYear().toString();
   month=(jsmonth + 1).toString();
   if (month.length != 2) {
     month="0" + month;
   }
   year=jsyear.substring(2,4)
   todayDate=(year + month + day);
   document.enews.dateSubscribe.value=todayDate;
   }
</script>

And then the form:

<form name="enews" method="post" action="yourprogram.cgi" onsubmit="return
getDate()">
<input type="hidden" name="dateSubscribe" value="020104" />
<input type="submit" name="date" value="Get Date" />
</form>

If you want to see it working, I put the code at:

http://evattmachado.com/testing/date.html

Hope this helps,

Josué


At 04:44 PM 2/15/2002 -0800, Bob Haroche wrote:
>I'm trying to use javascript to change the default value of a hidden field
>in a form to be the date on the user's computer and then pass that value to
>a cgi form processor. This is working in IE and NN 6 but not NN 4.
>
>Note that if the form field is changed from type="hidden" to type="input",
>everything works fine and NN correctly changes the value and that value is
>passed to the form.  However, if the field is type="hidden", the field value
>is processed as the default, un-changed value.
>
>Is it that NN can't/won't change the value of a hidden field or is something
>in my coding off?




More information about the thelist mailing list