Jump to content

[Resolvido] Função não fica disponível


Recommended Posts

Posted

Boas, eu tenho dois ficheiros, Newsletter.htm e mailer.js. O mailer.js é incluido no Newsletter.htm, mas quando tento utilizar num evento onClick de um input, a função não está disponível. É como se "a função estivesse fora do scope". Arranjei um solução, que foi executar a função da forma parent.minhaFuncao(parametros), mas o mais estranho, é que isto apenas funciona se a página não estiver dentro de frames, porque se estiver, a função deixa de estar disponível. Deixo aqui o código dos ficheiros. Quem me poder ajudar, agradecia.

Newsletter.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0055)http://www.minimalcomplex.com/newsletter/adm/mailer.php -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Newsletter</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT src="mailer.js" type=text/javascript></SCRIPT>

<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD> </TD></TR>
  <TR>
    <TD>
      <DIV class=titulo align=center>Enviar Email</DIV></TD></TR>
  <TR>
    <TD> </TD></TR>
  <TR>
    <TD>
      <DIV align=center>
      <FORM id=construtorMail name=construtorMail method=post>
      <TABLE class=tabelaFiltro cellSpacing=0 cellPadding=0 border=0>
        <TBODY>
        <TR>
          <TD>
            <DIV align=left>Utilizadores a quem enviar</DIV></TD>
          <TD width=5></TD>
          <TD>
            <DIV align=right><SELECT name=iDestinatarios> <OPTION 
              value=activos selected>Utilizadores activos</OPTION> <OPTION 
              value=inactivos>Utilizadores Inactivos</OPTION> <OPTION 
              value=todos>Todos os utilizadores</OPTION></SELECT> </DIV></TD></TR>
        <TR>
          <TD>
            <DIV align=left>Número de itens no email</DIV></TD>
          <TD width=5></TD>
          <TD>
            <DIV align=right><INPUT id=iNumModulos maxLength=2 size=4 
            name=iNumModulos></DIV></TD></TR>
        <TR>
          <TD>
            <DIV align=left>Assunto</DIV></TD>
          <TD width=5></TD>
          <TD>
            <DIV align=right><INPUT id=iAssunto size=35 
        name=iAssunto></DIV></TD></TR>
        <TR>
          <TD>
            <DIV align=left><INPUT onclick=javascript:limparModelo() type=button value="Limpar Modelo" name=limparModelo></DIV></TD>
          <TD width=5></TD>
          <TD>
            <DIV align=right><INPUT onclick="javascript:criarModelo(iDestinatarios.value, iNumModulos.value, iAssunto.value)" type=button value="Criar Novo Modelo" name=criarModelo></DIV></TD></TR></TBODY></TABLE></FORM></DIV></TD></TR>
  <TR>
    <TD> </TD></TR>
  <TR>
    <TD>
      <FORM action=mailer.php?func=enviar method=post>
      <DIV id=modelo 
align=center></DIV></FORM></TD></TR></TBODY></TABLE></BODY></HTML>

mailer.js

function criarModelo(iDestinatarios, iNumModulos, iAssunto) {
if (iNumModulos) { //gerar o modelo
	tmp = '<input type="hidden" name="iDestinatarios" value="'+iDestinatarios+'" /><input type="hidden" name="iNumModulos" value='+iNumModulos+' /><input type="hidden" name="iAssunto" value='+iAssunto+' /><table>';
	for(i=0; i<iNumModulos; i++) {
		tmp = tmp + '<tr><td class="caixaModulo"><div id="modulo'+i+'" align="center"></div></td></tr>';
	}
	tmp = tmp + '<tr><td align="center"><input type="button" name="previsualizar" value="Pré-visualizar" onClick="javascript:previsualizar()" /><input type="submit" name="enviarMail" value="Enviar Email" /></td></tr></table>';
	document.getElementById("modelo").innerHTML = tmp; //criar suporte para o modelo
	for(i=0; i<iNumModulos; i++) { //criar botoes do modelo
		inserirBotoesModulo(i);
	}
}
else alert('O email deve ter pelo menos um item.');
}

function limparModelo() {
document.getElementById("modelo").innerHTML = "";
}

function inserirBotoesModulo(iIndice) {
document.getElementById("modulo"+iIndice).innerHTML = 'AAAAAAA';
}

O problema está no botão Criar novo modelo. O botão pre-visualizar, ainda não está feito.

Posted

Já descubri o problema. Estava no nome da função e do input. Eram iguais, o que fazia com que a função ficasse indisponível.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.