understanding what i can do with onChange

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dan baker

    #1

    understanding what i can do with onChange

    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
  • @SM

    #2
    Re: understanding what i can do with onChange

    dan baker a ecrit :[color=blue]
    >
    > 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.[/color]

    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="onlyToRea d"
    value="Some text to test"
    onkeydown="truc =this.value;"
    onkeyup="this.v alue=truc;">
    <p>to modify the "virtual read only"
    <br>Enter your text here :
    <input type=text name="modificat or"
    onchange="onlyT oRead.value=thi s.value;" >
    and quit the field.
    <hr>
    <p><u><b>2nd test :</b></u>
    <p>a "real read only"
    <input type=text name="ToReadOnl y"
    value="Some text to test"
    readonly>
    <p>to modify the "real read only"
    <br>Enter your text here :
    <input type=text name="modificat eur"
    onchange="ToRea dOnly.value=thi s.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(do cument.getEleme ntById)
    document.getEle mentById('ToSee ').innerHTML=th is.value;">
    <div id="ToSee"></div>
    </form></html>

    [color=blue]
    > 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.[/color]

    Yes you have (ie for my NC4.5) to use regular form element.
    [color=blue]
    > 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[/color]

    --
    ******** (enlever/remove [OTER_MOI] du/from reply url) *******
    Stéphane MORIAUX : mailto:stephane OTER_MOImoriaux @wanadoo.fr
    Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

    *************** *************** *************** *************** **

    Comment

    Working...