|
|
CRO8
Bipolar (III) Inmate
From: New York City Insane since: Jul 2000
|
posted 08-15-2000 05:04
Hola
On www.hotfrogdesign.com/backgroundcolor.htm, I am trying to avoid repeating this loooooong string -> document.form1.chgcolor.value. I tried to use i = document.form1.chgcolor.value, but when it runs in the browser, I get the error message 'document.form1.chgcolor' is not an object. How can I get this to work properly?
Also, how come I didn't have to specify document.all for NS and document for IE? Or is it the other way around?
thanks so much!
|
mbridge
Paranoid (IV) Mad Scientist
From: Insane since: Jun 2000
|
posted 08-15-2000 06:03
stringName = 'document.form1.chgcolor.value';
I'm a newbie too, so don't take my word for it.
|
bitdamaged
Maniac (V) Mad Scientist
From: 100101010011 <-- right about here Insane since: Mar 2000
|
posted 08-15-2000 19:03
Hmm I can't get to that page right now.
Couple of points, IE and NN use different models so with IE you need the document.all where in NN you don't.
You may be getting this error in NN if you have embedded DIVs ex
<DIV ID="one">
<DIV ID="two">
</DIV>
</DIV>
in this case in IE you would call DIV two like this:
document.all.two.style
IN NN it becomes this:
document.one.document.two.
pain in the ass eh?
|
CRO8
Bipolar (III) Inmate
From: New York City Insane since: Jul 2000
|
posted 08-15-2000 23:52
bitDamaged
The link works, just delete the comma at the end of backgroundcolor.htm, <--
Thanks for your comments, but that is not the case. Please take some time and look at my page and tell me how to set i = document.form1.chgcolor.value.
Also, how do you instruct the browsers to locate text within a document. I want to locate font color. Somehting like this? document.font.color?
Probably won't work, but you get the picture.
Thanks a lot!
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 08-16-2000 01:23
Well, let's see...
One thing that I can think of is that you have to put the code
var i = document.form1.cngcolor.value
*inside* the validate() function. If you're trying to put it before the function, that would cause an error, because it's trying to access the form before the form has been created. So make sure it's inside the validate() function.
Honestly, that's all I can think of. Double check your spelling, of course... that will occasionally mess things up.
BTW, did you write the code yourself? It's pretty good for a beginner. Just one tip: instead of using "<!--" for comments inside your code (you use it to say "NOT EQUAL TO COLORS ON MY LIST"), use a double slash "//" instead; they both work in JavaScript but it's less confusing to the browsers to use the double slash.
|
CRO8
Bipolar (III) Inmate
From: New York City Insane since: Jul 2000
|
posted 08-16-2000 05:36
Slime
Alright! It worked when I placed the "var i=" string within the function validate(); . . . .very cool. And thanks for the compliment regarding my script, it takes a thousand questions, but I am slowly coming along.
MBridge thakns for your advice and good luck!
|
CRO8
Bipolar (III) Inmate
From: New York City Insane since: Jul 2000
|
posted 08-16-2000 06:14
Slime
Me again, since I have you now. . .I was wondering if you could lead me into the next stages of javascript that I could work on? I have books and all, but you've seen what I am starting to do. . . any ideas what to add to my current script so I can practice new code?
Thanks so much!
|
ocb
Bipolar (III) Inmate
From: Dublin, Ireland Insane since: Jun 2000
|
posted 08-16-2000 10:49
Javascript problemn for the day !
Try fading the bgColor from one user selected color to another using setTimeout commands. Get the user to enter six integer numbers between 0 and 255, convert these to hexadecimal, build two color strings out of the six (converted) hexadecimal numbers and fade the background gracefully between the two...
Points awarded for :
1. Compact code, especially the integer to hex conversion.
2. correct use of global vs local variables
Regards
Prof OCB.
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 08-16-2000 18:23
Hee hee, yeah, what he said.
After that, try working with more of the form input types. When I was at this stage I tried programming a couple of games; look at http://www.angelfire.com/ma/slimesareneat/games.html - these are what I came up with (the first two).
|
CRO8
Bipolar (III) Inmate
From: New York City Insane since: Jul 2000
|
posted 08-16-2000 20:45
ocb and slime
thanks for the challenge! I will do my best. First though, ocb- could you elaborate on what you said concerning the user picking anumber between 0 and 255, then converting it to hex#. Not quite sure what you mean by that.
Choose a combination like 3, 2, 45, 66 then make the page bg that hex color?
Thanks again.
CRO8
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 08-16-2000 21:37
Well, since the hexadecimal numbers 0 through FF are equal to the decimal numbers 0 through 255, he meant that you would take a decimal number and convert it into hexadecimal. For instance, in hexadecimal, 128 becomes 80 and 64 becomes 40. If the mathematics of this are over your head, you can just have them enter the hexadecimal number.
|
WarMage
Maniac (V) Mad Scientist
From: Rochester, New York, USA Insane since: May 2000
|
posted 08-17-2000 04:34
Anyone want to give me a quick lesson on the difference between local and global variables.
Not sure about the true meaning...
www.warmage.org
|
ocb
Bipolar (III) Inmate
From: Dublin, Ireland Insane since: Jun 2000
|
posted 08-17-2000 10:26
Warmage... methinks you are pulling my leg but...
Look at the sample code below :
<script language="javascript">
// Define our global variable
var globalOne=10
function someFunc()
{
// Now define a variable local to the function
var localOne=20
// Lets see what values the variables hold within the function
alert ("In the function, localOne's values is :"+localOne+" and globalOne's is"+globalOne)
}
// Lets see what values the variables hold outside the function
alert ("Outside the function, localOne's values is :"+localOne+" and globalOne's is"+globalOne)
// Call the function
someFunc()
</script>
If this script is placed into the head of an HTML document, you will see the first alert shows localOne to be null and globalOne's to be 10. Inside the function, localOne's will be 20 and globalOne's 10. This shows that a variable defined within a function holds it's value only within the function in question. Outside the function, it is 'out of scope'. globalOne's value holds fast nomatter where within the script it is read. This is because it has been declared globally, outside the function; therefore, it's value can be accessed (or it is said to be 'in scope') everywhere.
Hope that helps.
|