Announcement

Collapse
No announcement yet.

Javascript, anyone?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript, anyone?

    I dunno where this goes, but as far as tech forums go, this is one of the best ones I know of..

    So on with the request..
    This has been utterly pissing me off for the past three days, as I can't seem to get it right.

    This should be possible but I don't know how to work it correctly.

    First, I want to point to any word typed in a specific area as a variable for conducting an if/then condition

    I've set it up as:
    < a name="mood">Pissed< /a>
    (remove spaces in the codes)

    The problem is now getting javascript to recognize "Pissed" or whatever mood I type in there as a variable or string needed for the next set of instructions.

    I've tried about 50 ways and none of them seem to work.
    Some examples are
    document.mood
    document.link.mood
    document.links[mood]
    document.anchor.mood
    document.anchors[mood]

    I've even tried setting it up as a form, but it still doesn't work.

    I hope someone here knows what I'm trying to sya and can help..
    I'm close to setting some houses on fire..

  • #2
    I cant help you, but as I'm fighting with my own java script hell at the moment, if you buy the flamable liquid, I'll get the matches
    Juu nin to iro


    English doesn't borrow from other languages. It follows them down dark alleys, knocks them over, and goes through their pockets for loose grammar.

    Comment


    • #3
      Re: Javascript, anyone?

      Originally posted by DarkRogue
      I dunno where this goes, but as far as tech forums go, this is one of the best ones I know of..

      So on with the request..
      This has been utterly pissing me off for the past three days, as I can't seem to get it right.

      This should be possible but I don't know how to work it correctly.

      First, I want to point to any word typed in a specific area as a variable for conducting an if/then condition

      I've set it up as:
      < a name="mood">Pissed< /a>
      (remove spaces in the codes)

      The problem is now getting javascript to recognize "Pissed" or whatever mood I type in there as a variable or string needed for the next set of instructions.

      I've tried about 50 ways and none of them seem to work.
      Some examples are
      document.mood
      document.link.mood
      document.links[mood]
      document.anchor.mood
      document.anchors[mood]

      I've even tried setting it up as a form, but it still doesn't work.

      I hope someone here knows what I'm trying to sya and can help..
      I'm close to setting some houses on fire..
      Ok, here you go.

      document.[form name].[object name].[property];

      Make sure the form is either the only one or you name it. There are other variations to this but it should work. So if you want to put the value of an object named "mood" into a variable called myMood and your form is named "form" then the line would look like this.

      var myMood = document.form.mood.value;

      I find reading code helps in the learning process. The best place to get tons of useful examples is www.dynamicdrive.com. It is a good place to see good examples of crosss browser code as well.

      I hope this helps,
      Jeff
      Last edited by Duty; 22 October 2003, 22:42.
      -We stop learning when We die, and some
      people just don't know They're dead yet!

      Member of the COC!
      Minister of Confused Knightly Defence (MCKD)

      Food for thought...
      - Remember when naps were a bad thing?
      - Remember 3 is the magic number....

      Comment


      • #4
        First I would recommend using an ID attribute to identify the tag that you want to work with. Using a name attribute is not unique and referencing by name doesn't work for most tags. Since I don't think you want "Pissed" to be a link, a SPAN tag would be a better tag to use.


        &lt;span id="mood"&gt;Pissed&lt;/span&gt;

        ...

        &lt;script language="Javascript"&gt;
        var mood = document.getElementById('mood');
        alert("Your old mood was " + mood.innerHTML);
        mood.innerHTML = "Happy";
        &lt;/script&gt;


        document.getElementById is the new ECMAscript (Javascript 1.3) standard and will be supported by all future browsers.
        This code will work in IE5+, Gecko (Netscape 6, Mozilla, etc), Opera 5+, and Khtml (Safari, Konqueror) browsers. If you need to support IE 4, Netscape 4, and other javascript 1.1 compatible browsers, you will need to use document.all (IE) and document.layers (Netscape). Hopefully you don't need to.
        Last edited by piaxVirus; 22 October 2003, 23:10.
        I should have bought an ATI.

        Comment


        • #5
          Thanks, I tried all these but the thing is that my variable (mood) refuses to accept a value..

          Here it is again:

          Code:
          < span id="mood">Sad< /span>
          and for the script

          Code:
          var mood = document.getElementById('mood')
          document.write("currently set mood is "+ mood +"<br><br>")
          Result:
          currently set mood is null

          Sad
          so there.. it's not picking up the value for some reason.. everything I've tried so far isnt working..

          Comment


          • #6
            damn - you folks have convinced me that I should not get involved in any form of javascript AT ALL!
            Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

            Comment


            • #7
              Lol i'm sorry but it's cuz i'm still a newb to coding these things.
              I've only worked with very basic javascript and HTML.

              I'm trying to learn more coding (i just like making these things..even though they're a pain to learn without taking classes) and i'm running into a lot of problems..

              Once you get past a few hurdles it's pretty simple enough, just stuff like getElementById looks crazy, but they're words and self explanatory most of the time..

              Still i'm trying to find some answers.. i'm coding myself while waiting for some replies.

              Comment


              • #8
                That didn't work because your mood variable is only referencing the object for the &lt;span id="mood"&gt; tag. An object can contain many different properties, methods, and other objects. If you want to get the text inside the tags you need to use the .innerHTML property. e.g. mood.innerHTML

                If you want to learn more about ECMAscript (javascript) and DOM, here is a few sites to checkout.

                W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

                The World Wide Web Consortium (W3C) develops standards and guidelines to help everyone build a web based on the principles of accessibility, internationalization, privacy and security.




                I should have bought an ATI.

                Comment

                Working...
                X