Jump to content

Debugging


unknown gamer

Recommended Posts

Basically what i'm trying to do is check a Cookie to see if there is a username, if there is make a clear button and write the name.If it isn't it makes a box and submit button to set the cookie to the username entered. Everything but the clear button works. I am in Firefox and the debugging tool finds no syntax errors. Right now all it does is when clicked call a function which alerts something. I have no idea why it's not doing that. Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="content-type" content="text/html;charset=UTF-8"><title>Chat</title>	<script type="text/javascript" src="cookie.js"></script><script type="text/javascript">function clear(){alert("cleared");}function check(){	   if (navigator.cookieEnabled){		  userName = readCookie("user");}		if (userName){document.getElementById("enteru").type="hidden";document.getElementById("submit").type="hidden";document.getElementById("enterut").innerHTML="";		  document.getElementById("user_name").innerHTML=userName;}		else{		  document.getElementById("user_name").innerHTML="no username available";		  document.getElementById("enteru").type="text";document.getElementById("submit").type="submit";}}function setu(){var user = document.getElementById("enteru").value;if (user){ if (navigator.cookieEnabled){			  writeCookie("user", user, 5 * 365);alert("cookie set");}else{			  alert("Cookies aren't supported/enabled in your browser, which means I won't remember you later. I'm sorry.");}}}</script></head><body onLoad="check();"><label>username?</label><div id="user_name"></div><label id="enterut">Enter a username:</label><input type="text" id="enteru"><input type="submit" value="submit" id="submit" onClick="setu();"><input type="submit" value="clear" id="clears" onClick="clear();"></body></html>

Link to comment
Share on other sites

I'm wrong, though. Probably. I can't find it in any reserved word lists. PLUS:I can call clear() from the body tag (onload handler).I can call clear() from the script.I can assign clear to the button's click handler like this: document.getElementById("clears").onclick=clear;All these things work.But I cannot assign it with an onlick handler in a tag. Not an input tag, not a label tag, not a div tag.Of course, you shouldn't assign handlers in tags anyway.But this is weird. Maybe it's related somehow to the CSS attribute?

Link to comment
Share on other sites

It may not be a keyword, but it is a method of the document object:

<script type="text/javascript">alert(document.clear);</script>

Link to comment
Share on other sites

Excellent. According to MDC, it's a DOM-level 0 function that hasn't done anything since before Netscape 4. But it still exists, as the alert does indicate.Mystery solved, I would say.

Link to comment
Share on other sites

Excellent. According to MDC, it's a DOM-level 0 function that hasn't done anything since before Netscape 4. But it still exists, as the alert does indicate.Mystery solved, I would say.
I would agree with that.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...