Changing Textbox Value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Changing Textbox Value

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

comment out the return call in the function if you don't want it to actually submit..
Post Reply