Page 1 of 1

Changing Textbox Value

Posted: Mon Aug 23, 2004 3:31 pm
by TNIDBMNG
I have a hidden textbox and a button. When the button is pressed I want to add todays date to the textbox. Here is what I have but it's not working.

Code: Select all

<?php
<input type="hidden" name="txtDateVerified'.$id.'"><input type="Submit" name="btnVerified'.$id.'" value="Verified" onClick="addVerified(this.form,txtDateVerified'.$id.',''' . $id . ''')">
?>
and my javascript is

Code: Select all

&lt;script language="javascript"&gt;
function addVerified(frm,txt,id)&#123;
	
   dt = new Date();   
   month = dt.getMonth()+1;
   day = dt.getDate();
   year = dt.getFullYear();
   verifieddate = year + '-' + month + '-' + day;

   frm.txt.value = verifieddate;

&#125;
&lt;/script&gt;
Can someone tell me what I'm doing wrong. The date is fine but it tells me the txt is null.

Posted: Mon Aug 23, 2004 4:07 pm
by feyd

Code: Select all

addVerified(this.form,''txtDateVerified'.$id.''',''' . $id . ''')

-------------------

function addVerified(frm,txt,id)&#123;
   
   dt = new Date();   
   month = dt.getMonth()+1;
   day = dt.getDate();
   year = dt.getFullYear();
   verifieddate = year + '-' + month + '-' + day;

   var obj = frm.elements&#1111; txt ];

   if(obj)
     obj.value = verifieddate;
   else
     alert('bad name');

   return true;
&#125;

Posted: Mon Aug 23, 2004 4:16 pm
by TNIDBMNG
That worked great but as soon as it places the date in the hidden field the form refreshes itself and the date is gone.

Posted: Mon Aug 23, 2004 4:23 pm
by feyd
comment out the return call in the function if you don't want it to actually submit..