Problemas com javascript no php
É o seguinte galera...
Em alguns scripts meus em php, passei a utilizar vetores para melhorar a funcinalidade dos mesmos, mas estou tendo problemas com funções em javascript como no exemplo abaixo:
Neste exemplo, estou tentando validar o campo data_t com a função em javascript mascara_data_t
trecho do código em php:
<?php
/* Incrementando o nº de Itens (linhas) */
if ($acao=="Insere Linha") {
if ($itens >= 0 && $itens < 4) {
$itens += 1;
$pb_unitario=0;
}
$acao = NULL;
}
elseif ($acao=="Exclui Linha") {
if ($itens > 0) {
$itens -= 1;
}
$acao = NULL;
}
/* Laço das Linhas de Itens */
for ($i=0; $i <= $itens; $i++) {
?>
<tr align="center">
<td width="145" height="20"><input name="trecho_t[]" type="text" class="box6" value="<?php echo "$trecho_t[$i]"; ?>"></td>
***<td width="110" height="20"><input name="data_t[]" type="text" class="box5" onkeypress="mascara_data_t[](this);" maxlength="10" value="<?php echo "$data_t[$i]"; ?>"></td>***
<td width="115" height="20"><input name="hora_t[]" type="text" class="box5" value="<?php echo "$hora_t[$i]"; ?>"></td>
<td width="145" height="20"><input name="trecho2_t[]" type="text" class="box6" value="<?php echo "$trecho2_t[$i]"; ?>"></td>
<td width="110" height="20"><input name="data2_t[]" type="text" class="box5" maxlength="10" value="<?php echo "$data2_t[$i]"; ?>"></td>
<td width="115" height="20"><input name="hora2_t[]" type="text" class="box5" value="<?php echo "$hora2_t[$i]"; ?>"></td>
</tr>
<?php
/* Fim Laço */
}
?>
trecho da função em java script:
function mascara_data_t[]()
{
if (document.form.data_t[].value.length=="2")
{
document.form.data_t[].value = document.form.data_t[].value + "/"
}
if (document.form.data_t[].value.length=="5")
{
document.form.data_t[].value = document.form.data_t[].value + "/"
}
}
Já tentei de todas as formas possíveis e não consegui fazer funcionar.
Se alguém souber e poder me ajudar, ficarei muito grato!!!
Valeu
Discussão (3)
Carregando comentários...