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
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Mon Aug 23, 2004 3:31 pm
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
<script language="javascript">
function addVerified(frm,txt,id){
dt = new Date();
month = dt.getMonth()+1;
day = dt.getDate();
year = dt.getFullYear();
verifieddate = year + '-' + month + '-' + day;
frm.txt.value = verifieddate;
}
</script>
Can someone tell me what I'm doing wrong. The date is fine but it tells me the txt is null.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 23, 2004 4:07 pm
Code: Select all
addVerified(this.form,''txtDateVerified'.$id.''',''' . $id . ''')
-------------------
function addVerified(frm,txt,id){
dt = new Date();
month = dt.getMonth()+1;
day = dt.getDate();
year = dt.getFullYear();
verifieddate = year + '-' + month + '-' + day;
var obj = frm.elementsї txt ];
if(obj)
obj.value = verifieddate;
else
alert('bad name');
return true;
}
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Mon Aug 23, 2004 4:16 pm
That worked great but as soon as it places the date in the hidden field the form refreshes itself and the date is gone.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 23, 2004 4:23 pm
comment out the return call in the function if you don't want it to actually submit..