Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript need javascript help [1]

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #156579
    javascriptnewbie
    Participant
        <input placeholder="Password.." onfocus="y()" type="text"/>
    
    
    function y(){
    this.style.backgroundColor="red";
    }
    

    whys this not working, can someone help?

    #156586
    Alen
    Participant
    #156608
    TheDoc
    Member

    @Alen – I’m not exactly sure what you’re solving with that pen…

    Regardless, in your example you don’t need Javascript at all to accomplish what you’re trying to do. Styling is what CSS is for:

    input[type="text"]:focus {
        background: red;
    }
    

    Also there’s a proper input type for passwords:

    <input type="password" placeholder="Password" />
    

    http://codepen.io/ggilmore/pen/51dd201291632b5d45c631c53d13bb89

    #156611
    Alen
    Participant

    He edited the question to add input. But yeah at least he knows the pointless JavaScript approach. :)

    #156614
    Alen
    Participant

    getElementsByClassName returns an array of elements.

    Since our two boxes are different, we have to select them individually. If we had many box1 then you would have to use for loop to style them. Since we know we only have one item in the array, using [0] selects the element we want.

    http://codepen.io/alenabdula/pen/deAno

    #156630
    Alen
    Participant

    I guess you could do this: http://codepen.io/anon/pen/DifpE but the box[n] part becomes too ambiguous.

    #156660
    Alen
    Participant

    I do just didnt log in when I forked the pen.

    http://codepen.io/alenabdula

    And js is not my thing, am still learning.

    I know enough to know that I don’t know. Lol if that makes sense.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.