Javascript being akward

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator:Moderators

Post Reply
User avatar
hEAdAkE
Posts:15
Joined:Fri Mar 06, 2009 3:59 pm
Javascript being akward

Post by hEAdAkE » Fri May 08, 2009 11:02 am

So it all started out with me at my computer working on some JS when i decided to add a clear button to get rid of info in text boxes. so i put a button on my page (value="Clear!") and wrote the code, onclick"clear();".

<input type="button" value="Clear!" onclick="clear()">

Then i created a function that looked like this:

function clear() {
document.averages.abox.value="Average Here!"
document.averages.numberbox1.value=""
document.averages.numberbox2.value=""
document.averages.numberbox3.value=""
}

But it did not work when i tried it.
So, suspicious that i had used clear before, i checked for clear, but it wasnt any where on my page but those to places, so i tried changing the name to "clearem()" and changed them in both places. And it worked. I assumed that clear must be a restricted word, but it wasnt.

Does anyone have an answer to this akwardity of JS?
Falco upon hearing that Slippy and his fiancee are stranded on the water planet:

"What? Slippy's engaged? Like, to a woman?"

User avatar
samjc3
Posts:1086
Joined:Sun Feb 15, 2009 8:05 pm
Steam ID:samjc3
Location:burning and pillaging!!

Re: Javascript being akward

Post by samjc3 » Mon May 11, 2009 9:28 pm

thats java for ya. java<c_(insert + or ++ or leave it blank) :P
AfroLH wrote:
HotDog-Cart wrote: Also, the codename stuff adds a little bit of sexyness, in my eyes.
Yeah well Alcohol adds a little bit of sexyness in my eyes, but I dont drink it all the time. :wink:
SpongeBuell wrote:As proof, I offer this picture of a monkey on my head.

bobbypig
Posts:6
Joined:Sun Sep 06, 2009 10:04 am

Re: Javascript being akward

Post by bobbypig » Sun Sep 06, 2009 10:09 am

Javascript isn't awkward at all. It's just too lenient in some browsers:
the problem is that each line of javascript is supposed to end with a semicolon (;)

sometimes when you forget to end with ; browsers are able to figure out what you meant and the script seems to work.

This is very annoying when testing across all browsers, so just go down your code and check the ends of lines for semicolons.

Post Reply