Javascript Random GetElementById Junk
I have to say that I HATE javascript. While I can usually squirm my way through a php mess, my girlfriend can tell if I had done any work with javascript that day. She walk in and I’ll be pale, holding my knees to my chest, and sucking my thumb. She’ll say “Oh, you did javascript todayâ€.
I don’t think javascript is really that hard. I just haven’t taken the time to learn it. I only use if for stuff like form validation and various other miscellaneous client-side jobs. However, to me php usually makes sense. It’s style of logic is similar to mine. Javascript’s logic is similar to that of my girlfriend. (This isn’t exactly accurate because javascript is a computer language and at least will eventually make sense when I get it all working. My girlfriend will never make sense.)
Here’s one thing I hate about javascript:
I’m sure there is a good reason for this. I wish the people who write the tutorials would put a little more time into explaining why javascript does it this way, because it doesn’t make a bit of sense to me. In fact, the main reason I’m writing this blog is so I can remember this “quirkâ€.
GetElementByID
If you want to snag a value of any item at any time in javascript, you can use the GetElementByID method to snag that value it and do stuff with it. (What kind of stuff? You can determine if that value is what you want it to be and therefore allow a form to be disabled if it doesn’t. You can use css to change the css of an item or even remove that item)
var reasoncheck=document.getElementById(\"reason\").value;
However, the code above will not work with a textarea form field. Why? You’ve got me! So, if I want to snag the value of a textarea, I have to do it like this:
var reasoncheck = document.formbuy.reason.value;