Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #40372 > unrolled thread

changing the value of a text box with .js

Started bybill <william@TechServSys.com>
First post2021-09-05 14:17 -0400
Last post2021-09-06 15:09 +0200
Articles 5 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  changing the value of a text box with .js bill <william@TechServSys.com> - 2021-09-05 14:17 -0400
    Re: changing the value of a text box with .js Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-09-05 22:44 +0000
      Re: changing the value of a text box with .js JJ <jj4public@gmail.com> - 2021-09-06 14:39 +0700
        Re: changing the value of a text box with .js Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-09-17 00:46 +0200
    Re: changing the value of a text box with .js Arno Welzel <usenet@arnowelzel.de> - 2021-09-06 15:09 +0200

#40372 — changing the value of a text box with .js

Frombill <william@TechServSys.com>
Date2021-09-05 14:17 -0400
Subjectchanging the value of a text box with .js
Message-ID<sh31k5$167f$1@gioia.aioe.org>
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

[toc] | [next] | [standalone]


#40373

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-09-05 22:44 +0000
Message-ID<slrnsjai2s.78u.jon+usenet@raven.unequivocal.eu>
In reply to#40372
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.

[toc] | [prev] | [next] | [standalone]


#40374

FromJJ <jj4public@gmail.com>
Date2021-09-06 14:39 +0700
Message-ID<tx928w8dphta$.1jplgn5qs6ioi.dlg@40tude.net>
In reply to#40373
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.

[toc] | [prev] | [next] | [standalone]


#40387

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2021-09-17 00:46 +0200
Message-ID<5497567.DvuYhMxLoT@PointedEars.de>
In reply to#40374
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.

[toc] | [prev] | [next] | [standalone]


#40375

FromArno Welzel <usenet@arnowelzel.de>
Date2021-09-06 15:09 +0200
Message-ID<ipmi8nF3c0vU1@mid.individual.net>
In reply to#40372
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web