3
Is the following:
I have an index.html page where the user selects a certain amount through radio input.
Clicking on GENERATE runs a function where via Document.write a form is created according to the value selected by the user previously. That is, you selected 2, appears 2 forms, etc...
My problem is with the masks on this form. (Date and RG) I assembled the page generated through the function in pure HTML and the masks work smoothly.
Basically it is: I have a.js file and I want to call another.js file from it. I’ve tried unescape, I don’t know if I made wrong use of the syntax, even because it’s discontinued, or doesn’t work, I don’t know...
I searched several forums, found basically the same answer and nothing worked so far. As I am new to javascript, I must be doing something wrong or letting some detail pass.
I hope you can help me.
I appreciate the answers so far.
The answers so far look nothing like what I did. T_T
This is the index.html page where the user chooses the amount.
<body>
<div class="body">
<div class="content_body">
<div class="logo">
<img src="img/logo.png">
</div>
<div class="title">
QUANTAS CREDENCIAS VOCÊ GOSTARIA DE GERAR?
</div>
<div class="options">
<form>
<p><label> 1 </label><br>
<input name="Opc" value="1" type="radio"/></p>
<p><label> 2 </label><br>
<input name="Opc" value="2" type="radio"/></p>
<p><label> 3 </label><br>
<input name="Opc" value="3" type="radio"/></p>
<p><label> 4 </label><br>
<input name="Opc" value="4" type="radio"/></p>
<p><label> 5 </label><br>
<input name="Opc" value="5" type="radio"/></p>
</form>
</div>
<div class="submit">
<input onclick="qtdd()" type="submit" value="GERAR"/>
</div>
</div>
</div>
</body>
Below is the page that is created by clicking on "GENERATE".
(I only put the HTML, but there is the verification of which field is checked)
document.write(
"<html>" +
"<head>" +
"<link rel='stylesheet' type='text' href='css/credencial.css'/>" +
"<meta charset='UTF-8'/>" +
"<link rel='shortcut icon' href='img/logo.ico' type='image/x-icon'>" +
//Linkar javascript aqui
"</head>" +
"<body>" +
"<div class='body'>" +
"<div class='content_body'>" +
"<div class='logo'>" +
"<img src='img/logo.png'>" +
"</div>" +
"<div class='title'>" +
(1+i) + "° CREDENCIAL - FRENTE " +
"</div>" +
"<div class='frente'>" +
"<form>" +
"<p><label> NOME: </label></p>" +
"<input autofocus type='text'>" +
"<p><label> CARGO: </label>" +
"<input type='text'></p>" +
"<p><label> RECEBIDO POR: </label></p>" +
"<input type='text'>" +
"</div>" +
"<div class='title'>" +
(1+i) + "° CREDENCIAL - VERSO " +
"</div>" +
"<div class='verso'>" +
"<p class='form2'><label> RG: </label><br>" +
"<input type='text' id='rg'>   </p>" +
"<p class='form2'><label> ESTADO CIVIL: </label><br>" +
"<select>" +
"<option value=' ' title='Nenhum'> </option>" +
"<option value='Solteiro(a)'> Solteiro(a) </option>" +
"<option value='Casado(a)'> Casado(a) </option>" +
"<option value='Divorciado(a)'> Divorciado </option>" +
"<option value='Viúvo(a)'> Viuvo(a) </option>" +
"</select>" +
"<p class='form2'><label> DATA DE NASCIMENTO: </label><br>" +
"<input id='dtn' type='text'>   </p>" +
"<p class='form2'><label> ESTADO: </label><br>" +
"<select>" +
"<option value=' ' title='Nenhum'> </option>" +
"<option value='Acre' title='Acre'> AC </option>" +
"<option value='Alagoas' title='Alagoas'> AL </option>" +
"<option value='Amapá' title='Amapá'> AP </option>" +
"<option value='Amazonas' title='Amazonas'> AM </option>" +
"<option value='Bahia' title='Bahia'> BA </option>" +
"<option value='Ceará' title='Ceará'> CE </option>" +
"<option value='Distrito Federal' title='Distrito Federal'> DF </option>" +
"<option value='Espírito Santo' title='Espírito Santo'> ES </option>" +
"<option value='Goiás' title='Goiás'> GO </option>" +
"<option value='Maranhão' title='Maranhão'> MA </option>" +
"<option value='Mato Grosso' title='Mato Grosso'> MT </option>" +
"<option value='Mato Grosso do Sul' title='Mato Grosso do Sul'> MS </option>" +
"<option value='Minas Gerais' title='Minas Gerais'> MG </option>" +
"<option value='Pará' title='Pará'> PA </option>" +
"<option value='Paraíba' title='Paraíba'> PB </option>" +
"<option value='Paraná' title='Paraná'> PR </option>" +
"<option value='Pernambuco' title='Pernambuco'> PE </option>" +
"<option value='Piauí' title='Piauí'> PI </option>" +
"<option value='Rio de Janeiro' title='Rio de Janeiro'> RJ </option>" +
"<option value='Rio Grande do Norte' title='Rio Grande do Norte'> RN </option>" +
"<option value='Rio Grande do Sul' title='Rio Grande do Sul'> RS </option>" +
"<option value='Rondônia' title='Rondônia'> RO </option>" +
"<option value='Roraima' title='Roraima'> RR </option>" +
"<option value='Santa Catarina' title='Santa Catarina'> SC </option>" +
"<option value='São Paulo' title='São Paulo'> SP </option>" +
"<option value='Sergipe' title='Sergipe'> SE </option>" +
"<option value='Tocantins' title='Tocantins'> TO </option>" +
"</select>   </p>" +
"<p class='form2'><label> BATISMO: </label><br>" +
"<input type='text' id='batismo'>   </p>" +
"<p class='form2'><label> VALIDADE: </label><br>" +
"<input type='text' id='validade'>   </p>" +
"<div class='limpar'>" +
"<input type='reset' value='LIMPAR'/>" +
"</div>" +
"</form>" +
"</div>" +
"</div>" +
"</div>" +
"</body>" +
"</html>"
)
}
document.write(
"<div class='submit'>" +
"<div class='btnsub'>"+
"<input onclick='validacao()' type='submit' value='ENVIAR'/>" +
"</div>" +
"</div>"
)
return
}
}
for(i=0; i<qtd.length; i++){
if(qtd[i].checked == false){
alert("VOCÊ PRECISA ESPECIFICAR A QUANTIDADE!")
return
}
}
I even understood what you proposed, but I don’t think it’s quite what I wanted.
Ali in //Linkar javascript, I would like to put this:
<script type="text/javascript" src="lib/jquery.js"></script>
<script src="lib/maskedinput-1.3.js" type="text/javascript"></script>
<script src="lib/mascara.js" type="text/javascript"></script>
However, with "all" the options and my capacity exhausted, I have no idea.
I have the impression that it is something silly and simple, but I can not solve.
I have tried creating through DOM, concatenate the "scr" + "ipt" and nothing.
I accept tips, criticism, suggestions.
Without seeing your code it becomes difficult to answer... But anyway, I suggest you review your strategy: why not, for example, put all Javascript in one file, and when this new content is inserted into the DOM (tip: prefer
el.appendChild
instead ofdocument.write
) you manually assign references to Event listeners? An even better option - if you are using jQuery - would be to use generic functions, which deal with all the elements that satisfy a certain filter, current or future. This is done through$.on
. Just a few suggestions.– mgibsonbr