Forums

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

Home Forums JavaScript Can’t change textarea to input

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44089
    botpro7
    Member

    Hi guys, i’ve been trying to customizing this virtual keyboard but have no clue what is wrong.

    If i change
    <textarea id=”write” type=”password” rows=”1″ cols=”30″></textarea>
    to
    <input id=”write” type=”password”/> the virtual keyboard isn’t working.

    Could anyone please help me how to solve this? Thanks in advanced.

    Please check this out
    [http://jsfiddle.net/rhXx8/2/](http://jsfiddle.net/rhXx8/2/ “Virtual Keyboard JQuery”)

    #131688
    CrocoDillon
    Participant

    The function changes what’s inside the element, which works for textareas but not for inputs because they are empty elements. You can set the value attribute on inputs though.

    EDIT: After a quick test, setting the value attribute isn’t ideal either.

    EDIT: Actually it does work, with jQuery’s `val` function (I tried `attr(‘value’)` first)

    http://jsfiddle.net/rhXx8/3/

    #131706
    botpro7
    Member

    thanks CrocoDillon, it works. But i don’t understand why is it input elements are empty elements? If u don’t mind could you please give me an insight or reference somewhere on the net? Thanks again :)

    #131711
    CrocoDillon
    Participant

    Normally elements can have other elements, text or comments inside them (between the opening and closing tags), for example `` where the textarea has some text inside it. You can set whatever is inside an element with jQuery’s `.html()` function.

    Input elements are empty or self-closing elements, in xhtml that would be obvious with a slash right before the right bracket ``, in html5 both with or without the slash are valid. Anyway because they are empty elements `.html()` does nothing.

    Empty elements can have attributes though.

    Googling I found [this short explanation](http://www.456bereastreet.com/archive/201005/void_empty_elements_and_self-closing_start_tags_in_html/), maybe it helps :)

    #131712
    botpro7
    Member

    aha! you have enlightened me. That’s why i have to use .val to get the value out instead of .html. Thank you. :)

    #131714
    CrocoDillon
    Participant

    Yes, `val()` gets or sets whatever kind of value the form element is using, not sure how it works under the hood, don’t really care either… for now :)

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