0

need BIG help. How to get the value of LABEL tag in my view page? I have a Daily Time Record project that lets you input your Employee Number and a LABEL TAG that display real-time DATE and Time via javascript. What i want is to save into the database the employee num together with the value of label tag.

CREATE TABLE `dtr_attendances` (
`id` INTEGER NOT NULL AUTO_INCREMENT  PRIMARY KEY,
`employee_num` varchar(20),           
`date_time` varchar(40),          
`particular` varchar(30),
`notes` varchar(40),
`created`  DATETIME, 
`modified` DATETIME ,
`username` VARCHAR(30)
) ENGINE=innodb DEFAULT CHARSET=utf8;

My JAVASCRIPT:

function date_time(id,id2){

date = new Date;
year = date.getFullYear();
month = date.getMonth();
months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',      
'September', 'October', 'November', 'December');
d = date.getDate();
day = date.getDay();
days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
h = date.getHours();
if(h<10){h = "0"+h;}
m = date.getMinutes();
if(m<10){m = "0"+m;}
s = date.getSeconds();
if(s<10){s = "0"+s; }
result = ''+days[day]+' '+months[month]+' '+d+' '+year+' '+h+':'+m+':'+s;
document.getElementById(id).innerHTML = result;
document.getElementById(id2).innerHTML = result;
setTimeout('date_time("'+id+'");','1000');
return true;
}

In my INDEX.CTP:

<?php echo $this->Form->create('DtrAttendance' , array('action' => 'index')); ?> 
<div  style="background-color:#FFA500;clear:both;text-align:center;height:500px">       
<?php echo $this->Form->input('employee_num'); ?> </br>
<?php $this->Form->hidden('notes');?>   
<label id="date_time" font-size="50px"> </label>        
<script type="text/javascript">window.onload = date_time('date_time','notes');     </script>            
</div>

IN CONTROLLER:

public function index() {

if ($this->request->is('post')) {

$this->DtrAttendance->create();     
$this->DtrAttendance->set(array(  'particular'=>'My  particular',
'username'=>'MyUsername',  
'created'=>date('Y-m-d H:i:s')));   
if ($this->DtrAttendance->save($this->request->data)) 
}

How to code IT in my controller to get the value of LABEL TAG

4

1 回答 1

0

The label text is not submitted with the form. If you need this value, perhaps you could also have a hidden input, and your Javascript could update both the label text and hidden form field?

于 2013-06-11T08:55:50.057 回答