• changing the value of a text box with .js

    From bill@21:1/5 to All on Sun Sep 5 14:17:41 2021
    I know how to change the value of a span or div using:
    onClick= document.getElementById("searchkey").value = "type min 3
    letters";

    but that does not work for an input type=text element.

    What is the proper way to do that?

    -bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to bill on Sun Sep 5 22:44:44 2021
    On 2021-09-05, bill <william@TechServSys.com> wrote:
    I know how to change the value of a span or div using:
    onClick= document.getElementById("searchkey").value = "type min 3
    letters";

    but that does not work for an input type=text element.

    What is the proper way to do that?

    Did you mean that the other way around? If so you might want the
    'textContent' property.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Jon Ribbens on Mon Sep 6 14:39:07 2021
    On Sun, 5 Sep 2021 22:44:44 -0000 (UTC), Jon Ribbens wrote:
    On 2021-09-05, bill <william@TechServSys.com> wrote:
    I know how to change the value of a span or div using:
    onClick= document.getElementById("searchkey").value = "type min 3
    letters";

    but that does not work for an input type=text element.

    What is the proper way to do that?

    Did you mean that the other way around? If so you might want the 'textContent' property.

    And make sure correct quoting is used. Use HTML entity and escape sequence
    if necessary.

    Cause, the provided sample code will never work, regardless of what HTML tag/element it is on.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Mon Sep 6 15:09:43 2021
    bill:

    I know how to change the value of a span or div using:
    onClick= document.getElementById("searchkey").value = "type min 3
    letters";

    <span> or <div> don't have a value. What are you talking about?

    but that does not work for an input type=text element.

    What is the proper way to do that?

    Using "value" is totally fine:

    <input type="text" id="foobar" name="foobar">

    <script>
    document.getElementById("foobar").value="test";
    </script>

    However - where exactly do you use "onClick" and did you define
    "searchkey" as *id* and not only as name?


    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas 'PointedEars' Lahn@21:1/5 to All on Fri Sep 17 00:46:48 2021
    JJ wrote:

    On Sun, 5 Sep 2021 22:44:44 -0000 (UTC), Jon Ribbens wrote:
    On 2021-09-05, bill <william@TechServSys.com> wrote:
    I know how to change the value of a span or div using:
    onClick= document.getElementById("searchkey").value = "type min 3
    letters";

    “span” or “div” elements do not have a built-in “value” property.

    but that does not work for an input type=text element.

    *That* should work, though, as the corresponding object *does* have a built-
    in value property.

    What is the proper way to do that?

    Did you mean that the other way around? If so you might want the
    'textContent' property.

    And make sure correct quoting is used. Use HTML entity and escape sequence
    if necessary.

    Cause, the provided sample code will never work, regardless of what HTML tag/element it is on.

    By contrast to the “innerHTML” property, the “textContent” property does not
    require any escaping beyond the one required for a syntactically correct ECMAScript program; indeed, if you HTML-escape the value assigned to it, the escape sequences will be displayed verbatim.

    --
    PointedEars
    FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
    Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)