473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Replace text in text box with innerhtml type thing

Currently, I am having a problem replacing the value of a input box
with something else using the innerHTML thing. Right now I have
something going

<script type="text/javascript"><!--
function changeText(newText){
document.getElementById("WHATEVER").innerHTML=newT ext
}
//-->
</script>

and a link with

<a href='javascript:changeText("Hola Mi Amigo")'>Dont know</a>

and the text box like

<INPUT TYPE="TEXT" NAME="WHATEVER" id="WHATEVER" VALUE="TESTING"
SIZE=60">

and I am trying to replace what is enterd in the text box with "Hola Mi
Amigo." However, it doesnt seem to want to do it. Maybe I am doing
something wrong, but I have no idea what my problem is.

Aug 2 '06 #1
7 15407

bo*****@gmail.com wrote:
Currently, I am having a problem replacing the value of a input box
with something else using the innerHTML thing. Right now I have
something going

<script type="text/javascript"><!--
Do not use HTML-style comments inside script elements, they are a
complete waste of time.

function changeText(newText){
document.getElementById("WHATEVER").innerHTML=newT ext
innerHTML is proprietary DOM element property introduced by IE. It has
been widely copied (though inconsistently) and represents the HTML
between the start and end tags of an element - i.e. it's HTML content.

}
//-->
</script>

and a link with

<a href='javascript:changeText("Hola Mi Amigo")'>Dont know</a>
Using the javascript pseudo-protocol as the value of an href attribute
is a bad idea. If you want to use an A element, use an onclick
attribute with return false to cancel navigation:

<a href="#" onclick="changeText('Hola Mi Amigo');return false;">Dont
know</a>

and the text box like

<INPUT TYPE="TEXT" NAME="WHATEVER" id="WHATEVER" VALUE="TESTING"
SIZE=60">
As noted above, the innerHTML property of an element represents its
HTML content. Since INPUT elements don't have any content, it's
difficult to say what the browser will make of assigning some HTML to
its innerHTML property. There is no public specification that says how
to handle it, so implementations may differ.

It is likely, but not guaranteed, that they will simply ignore it.

If you are trying to change the text that appears in the text input,
then change the input's value attribute.

and I am trying to replace what is enterd in the text box with "Hola Mi
Amigo." However, it doesnt seem to want to do it. Maybe I am doing
something wrong, but I have no idea what my problem is.
<a href="#" onclick="
document.getElementById('WHATEVER').value = 'Hola Mi Amigo';
return false;
">Dont know</a>
Feature detection omitted for brevity.
--
Rob

Aug 2 '06 #2
RobG wrote:
>
<a href="#" onclick="
document.getElementById('WHATEVER').value = 'Hola Mi Amigo';
return false;
">Dont know</a>

RobG I agree with you, though I may add that inline Javascripts inside
HTML tags should be limited to function calls. This way, separation
between HTML design and Script design is more well defined.

thus : <a onclick="changeText('Hola Mi Amigo');">Don't know</a>

(NOTE : http://www.w3.org/TR/html401/struct/links.html states that <a>
-- anchor -- tags don't have to have a href property...)

or :

<a id="someId">Don't know</a>

<script type="text/javascript">
document.getElementById('someId').onclick = function() {
changeText('Hola Mi Amigo'); };
</script>

Error detections omitted for clarity.

Aug 2 '06 #3
Yanick wrote:
RobG wrote:
>>
<a href="#" onclick="
document.getElementById('WHATEVER').value = 'Hola Mi Amigo';
return false;
">Dont know</a>

RobG I agree with you, though I may add that inline Javascripts inside
HTML tags should be limited to function calls. This way, separation
between HTML design and Script design is more well defined.
That is not a practical suggestion, and likely to promote the
misconception that functions called in the code of intrinsic event
attributes are the actual event handlers, instead of the functions
internally generated by the browser from those values.
thus : <a onclick="changeText('Hola Mi Amigo');">Don't know</a>

(NOTE : http://www.w3.org/TR/html401/struct/links.html states that <a>
-- anchor -- tags don't have to have a href property...)
<snip>

But without the HREF attribute the A element will be unreachable by
keyboard navigation (an accessibility issue), and with an HREF it will
probably need - return changeText(" ... "); in order to cancel the
navigation (denying the possibility of using only the function call).

Richard.

Aug 2 '06 #4
>
That is not a practical suggestion, and likely to promote the
misconception that functions called in the code of intrinsic event
attributes are the actual event handlers, instead of the functions
internally generated by the browser from those values.
Sure, <a id="someAnchor" href="#" onlick="changeText('blah'); return
false;">Don't know</ais in fact :
document.getElementById('someAnchor').onclick = function(event) {
changeText('blah'); return false; }; And I agree that it may promote
misunderstood concepts of DOM events, but it is, in my opinion, also a
bad coding practice to mix JS with HTML. Personnally, I use event
attributes inside HTML tags not very often.

It is the responsibility of every programmer to understand how the
language works before building programming habbits. (And I do not
exempt myself here.) Avoiding using function calls over inline
javascript, so it doesn't confund the newbies about event handlers is
not, in my point of view, a valid excuse. That's all.

By the way, I did not know about the href being used for keyboard
accessibility issues (doesn't make any sense to me still...). This
aspect is not covered in the W3C document.

Aug 3 '06 #5
Yanick wrote:
>That is not a practical suggestion, and likely to
promote the misconception that functions called in
the code of intrinsic event attributes are the actual
event handlers, instead of the functions internally
generated by the browser from those values.

Sure, <a id="someAnchor" href="#" onlick="changeText('blah');
return false;">Don't know</ais in fact :
document.getElementById('someAnchor').onclick = function(event) {
changeText('blah'); return false; }; And I agree that it may promote
misunderstood concepts of DOM events, but it is, in my opinion, also a
bad coding practice to mix JS with HTML.
But if you put any code in the intrinsic event attributes you are mixing
javascript and HTML, so recommending only putting function calls in
those attribute values is already a compromise, and having already
compromised it makes most sense to carry the compromise on to the point
where cancelling the default actions of events becomes easy (as that is
something that is often going to be wanted).

<snip>
By the way, I did not know about the href being used for
keyboard accessibility issues (doesn't make any sense to
me still...).
You have never seen anyone using the tab key to switch from link to link
in an HTML page?
This aspect is not covered in the W3C document.
Which document would you expect to cover it? The WCAG 1.0 document
certainly requires that all actions that can be initiated with a
pointing device also be initiated with a keyboard, and to 'click' a link
with a keyboard you need to be able to first pass focus to that link
using the keyboard (i.e. tabbing to the link).

Richard.
Aug 3 '06 #6
bo*****@gmail.com wrote:
Currently, I am having a problem replacing the value of a input box
with something else using the innerHTML thing. Right now I have
something going

<script type="text/javascript"><!--
function changeText(newText){
document.getElementById("WHATEVER").innerHTML=newT ext
}
//-->
</script>

and a link with

<a href='javascript:changeText("Hola Mi Amigo")'>Dont know</a>

and the text box like

<INPUT TYPE="TEXT" NAME="WHATEVER" id="WHATEVER" VALUE="TESTING"
SIZE=60">

and I am trying to replace what is enterd in the text box with "Hola Mi
Amigo." However, it doesnt seem to want to do it. Maybe I am doing
something wrong, but I have no idea what my problem is.
Since you're using a text-input, it will have a "value" property that
is settable as well as gettable. Since it's just plain text that you
want to write, the .value property is fine.

<script>
function changeText(newText)
{ document.getElementById("WHATEVER").value = newText; }
</script>

hth

http://darwinist.googlepages.com/htmldesktop.html
(A free, open-source web-based IDE, windowing system, and desktop
environment, in 31kB of html and javascript.)

Aug 4 '06 #7
But if you put any code in the intrinsic event attributes you are mixing
javascript and HTML, so recommending only putting function calls in
those attribute values is already a compromise, [...]
I'm not entirely a radical person :) I agree to make compromises to
some point of view... Calling a function, then adding a "return false;"
does not create any long term issue in the code. The idea behind
limiting javascript inside event attributes of HTML elements is to put
as much of the js commands at the same place in the document as
possible. Perhaps, even, if that event has to be modified, the HTML
portion won't have to be... But in general, I would think that we agree
on this.
>
You have never seen anyone using the tab key to switch from link to link
in an HTML page?
Sure, I've been using tabs some times. I even used Lynx a few times...
I simply didn't know that anchors skipped tabs when href is omitted
(which is, in my opinion, pretty stupid as it is an "anchor"). It's
always good to know.

Aug 4 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: gbit | last post by:
Hi, I have a web page describing a procedure using generic names. At the top of the page I have a text box. When the user enters a specific name in the text box, I would like the page to...
1
by: Kevin | last post by:
Hello, Does anyone know how to implement find and replace in a RichTextBox in a way that does not lose the text formatting? As a first attempt I tried rtb.Rtf.Replace(sFindText,...
1
by: Suresh Tri | last post by:
Hi, I was trying to overload concat operator ||(text,text) such a way that it behaves like Oracle. i.e. I want 'abc' || null to return 'abc' instead of null. I know that it is not the expected ...
2
by: Johann Robette | last post by:
Hi, I'm trying to call the array_to_string function like this : SELECT array_to_string(array, '~^~') --> it comes directly from the doc. I get this error msg : ERROR: parser: parse error at...
4
by: David Garamond | last post by:
What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do...
4
by: ijyoung | last post by:
Want to change text formatting in textarea with an onsubmit. I have the script working with the onchange command as follows: <form action="message.php" method="post"> <table align="center"...
7
by: kushaldutt | last post by:
Hi all, I am having trouble finding and replacing text in a xml file. My issue is I have to find a text in a xml file and change it to some other text. But the text in some element tag for ex:...
4
by: alexvorn2 | last post by:
Hi! I use VB 2008 and I want to ask you how I can replace the text that is between "*" and "*" in a text file? If text file contains this: *dog* *cat* *bird* *lion* *something* .....end of...
2
by: King of the R.O.U.S.'s | last post by:
Hi All How do I replace selected text in a textarea with JavaScript? I have a text area that the user can select what they want then press a button that will pick up the selected text, make...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.