...

View Full Version : Javascript and dynamic DIV display



sgalmeida
01-07-2004, 02:48 PM
Greetings,

I have a PHP function that outputs a Javascript function that verifies if a certain field is a digit or not. I want to, if it is not a digit, a DIV is shown with a custom message (is prettier than an JS alert). If I do this the way you can see bellow, I loose the page I was seeing; on source page I see only the DIV from isDigito(valor,campo) uutput. How can I do to not loose the rest of the page?
How can I do, using Javascript, do display DIV without loosing the rest of the page?

Thanks
Sérgio


<?
function JS_isDigito(){
?>
<script LANGUAGE='JavaScript'>
<!-- Begin
function isDigito(valor,campo){
var digits='0123456789'
var temp

for (var i=0;i<valor.value.length;i++){
temp=valor.value.substring(i,i+1)
if (digits.indexOf(temp)==-1){
/*alert("O campo '"+campo+"' deve ser preenchido apenas com números!")
valor.value=""
valor.focus()
*/

document.write("<div id=\"Alert\" style=\"position:absolute; width:300px; height:141px; z-index:1; overflow: hidden; left: 357px; top: 354px; visibility: visible;\"> ");
document.write("<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("<tr>");
document.write("<td><img src=\"img/AlertTopo.gif\" width=\"300\" height=\"15\"></td>");
document.write("</tr>");
document.write("</table>");
document.write("<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"img/AlertMeio.gif\">");
document.write("<tr>");
document.write("<td height=\"30\"><div align=\"center\"><? echo $GLOBALS['divAlertMinutesText']; ?></div></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td height=\"30\"><div align=\"center\">");
document.write("<input name=\"Submit22\" type=\"submit\" class=\"op\" onClick=\"MM_showHideLayers('Alert','','hide')\" value=\"Fechar\">");
document.write("</div></td></tr><tr> <td>&nbsp;</td></tr></table>");
document.write("<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("<tr> <td><img src=\"img/AlertBaixo.gif\" width=\"300\" height=\"15\"></td>");
document.write("</tr></table></div>");


return false
}
}
return true;
}
// End -->
</script>
<?
}
?>

A1ien51
01-07-2004, 02:52 PM
You can not document.write after tha page is loaded.

What you need to do is have the divs already there when the page loads and use innerHTML to change the content of the div.

Eric

sgalmeida
01-07-2004, 03:39 PM
Hi,
can ou be a bit more specific abou the innerHTML?


Thanks

Sérgio



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum