Forum Moderators: open

Message Too Old, No Replies

Calling the value of a function?

         

toggo

7:50 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



Hey all, i have the following code, which seems to cease the page from loading once the script has been processed:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function lert(msg) {

alert(msg);

document.write(msg)

}
</script>
</head>

<body>

<input type="submit" name="Submit" value="Submit" onclick='lert("Hello World!")' />

</body>
</html>

The page displays the message "Hello World" in an alert box alright, and it then proceeds to print this value on the page, however, my browser's status bar seems to freeze on 50%?!?

Can anyone tell me why this is happening and how i would go about fixing it?

TIA
Toggo

kaled

12:34 am on Nov 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Strictly, you should use document.open(); document.write(); document.close();.

Also, alert() may be causing the problem.
Also, onclick should generally return either true or false but when using a submit button, the <form onsubmit> attribute should be used rather than onclick.
e.g. <form onsubmit='lert("Hello World!");return true;'>

Kaled.