By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,033 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,033 IT Pros & Developers. It's quick & easy.

understanding what i can do with onChange

P: n/a
I am pretty much a newbie with javascript, and would like to get a
little clarification on what I can do with an onChange javascript
event handler.

I have a dynamic page I build with perl and print to the browser which
includes some data displayed and edittable in <FORM> elements. There
are a couple areas where I display a message or a calculated total to
the user based on the initial values of some data elements.

I would like to clear or change the "read-only" messages and totals if
certain FORM elements get changed... and am unsure how to approach
this. It looks like if I display the "read-only" information in named
FORM elements I could use onChange event handlers to set the values...
but I don't really want the "read-only" or calculated fields to look
like regular FORM elements or allow editting.

Is there a way to use onChange to either:

- change the text in a specific area of a page that has already been
loaded using document.write() ? I am totally unsure if I have an
inline section of javascript that prints out a variable, and I change
the variable via onChange, if the text displayed would change without
refreshing the page.

- put my "calculated" values in FORM elements that look like they are
"read-only" but still allow me to change using the named object
elements?

thanks,
d
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
@SM
dan baker a ecrit :

I am pretty much a newbie with javascript, and would like to get a
little clarification on what I can do with an onChange javascript
event handler.
You can change the value of a read-only field via JavaScript
Except on my NC4.5 who doesn't know what is a readonly ...!

It is the only way to do it if you don't want to re-open (and php modify)

Try that :

<html>
<form>
<p><u><b>1st test :</b></u>
<p>a "virtual read only"
<input type=text name="onlyToRead"
value="Some text to test"
onkeydown="truc=this.value;"
onkeyup="this.value=truc;">
<p>to modify the "virtual read only"
<br>Enter your text here :
<input type=text name="modificator"
onchange="onlyToRead.value=this.value;" >
and quit the field.
<hr>
<p><u><b>2nd test :</b></u>
<p>a "real read only"
<input type=text name="ToReadOnly"
value="Some text to test"
readonly>
<p>to modify the "real read only"
<br>Enter your text here :
<input type=text name="modificateur"
onchange="ToReadOnly.value=this.value;" >
and quit the field.
<hr>
<input type=reset value="Reset">
</form></html>

No, you can't document.write on a document allready open
to be compatible with old browsers you must write in text-boxes or text-areas

If old browsers are not concerned
you can use the DOM

<html>
<form>
<p>a "writter on same document" :
<input type=text name="toWrite"
onchange="if(document.getElementById)
document.getElementById('ToSee').innerHTML=this.va lue;">
<div id="ToSee"></div>
</form></html>

I have a dynamic page I build with perl and print to the browser which
includes some data displayed and edittable in <FORM> elements. There
are a couple areas where I display a message or a calculated total to
the user based on the initial values of some data elements.

I would like to clear or change the "read-only" messages and totals if
certain FORM elements get changed... and am unsure how to approach
this. It looks like if I display the "read-only" information in named
FORM elements I could use onChange event handlers to set the values...
but I don't really want the "read-only" or calculated fields to look
like regular FORM elements or allow editting.
Yes you have (ie for my NC4.5) to use regular form element.
Is there a way to use onChange to either:

- change the text in a specific area of a page that has already been
loaded using document.write() ? I am totally unsure if I have an
inline section of javascript that prints out a variable, and I change
the variable via onChange, if the text displayed would change without
refreshing the page.

- put my "calculated" values in FORM elements that look like they are
"read-only" but still allow me to change using the named object
elements?

thanks,
d


--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.