Results 1 to 3 of 3

Thread: Java Script Problem

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Posts
    188

    Java Script Problem

    Hi

    I have a problem. I viewed the code of a website and found a line

    var challenge = form[".challenge"].value;

    I dont know what it means and will do after the declaration of the variable.

    moreover i want to know what does type=hidden do in input tag of a textbox.
    \"The Smilie Wars\" ... just arrived after the great crusades

    .... computers come to the rescue .... ah technology at last has some use.

  2. #2
    Senior Member
    Join Date
    Jul 2004
    Posts
    469
    That generically declares a variable named challenge, and assigns it the values of the field challenge in a form.

    If a field is hidden, its not displayed. This is a way for a webpage to retain information throughout your session without displaying it.

  3. #3
    Senior Member
    Join Date
    Jun 2002
    Posts
    394

    Re: Java Script Problem

    Originally posted here by Mystery Man
    Hi

    I have a problem. I viewed the code of a website and found a line

    var challenge = form[".challenge"].value;

    I dont know what it means and will do after the declaration of the variable.

    moreover i want to know what does type=hidden do in input tag of a textbox.
    that's interesting code.

    basically, in javascript, everything is an array, or you can think of everything as being like an array. i read that somewhere once.

    it's been a while since i've done any javascripting so i'm not sure on which browsers this works, but it should work on atleast one. consider the following:

    Code:
    <!-- some HTML "code" marking up "some text", giving it a colour -->
    <FONT id="CHALLENGE" color="#000000"> some text </FONT>
    Code:
    <!-- some javascript code to change the colour of the previous font tags contents-->
    document.all.CHALLENGE.color = '#FFFFFF';
    the document.all is an array containing all ID's declared in all the document! instead of using a numeric index you simply use the text value of the id property as the index. note that the string document.all.FONTID.color is interpreted literally. suppose you have a number of font tags with different ids and you want to use the contents of a variable to specify which font you want to change colour.

    Code:
    var myFontID = "CHALLENGE";
    document.all.myFontID.color = '#FFFFFF';
    the above, will not work because the string is interpreted literally, remember? there may or may not be an id called "myFontID". to rewrite the above example so that it works you will need to de-reference the variable so that it's contents are used instead it's name:

    Code:
    var myFontID = "CHALLENGE";
    document.all[ myFontID ].color = '#FFFFFF';
    ok, so it's probably all been quite clear what's going on with the original example for some time now, but i'll spell it out anyway. var challenge = form[".challenge"].value;. here the string is being derefferenced like the variable, and the strings contents are used to determiine which forms value to set equal to var challenge. i'm not sure if you need the '.' at the start. perhaps you do because it's not a variable dereference, it's a string constant.

    you can probably access the id elements like this too, but i'm not about to check either now. also, i can't remember ever needing to do it this way so it may not work:

    Code:
    <!-- just like a normal array -->
    document.all[ 0 ].color = '#FFFFFF';
    document.all[ 1 ].color = '#FFFFFF';
    dereferencing variables like that in javascript is pretty cool.
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •