Reaonly Property

Results 1 to 3 of 3

Thread: Reaonly Property

  1. #1
    Join Date
    Dec 1969

    Default Reaonly Property

    Is there anyone know how to set a textbox to readonly using client-side script? For example, when i click on a button, all the textboxes in the page become readonly...<BR><BR>Thankz in advance...

  2. #2
    Join Date
    Dec 1969

    Default RE: Reaonly Property

    Set up a function to call from all the text boxes first...<BR><BR>Then you click the main button have it set a variable to false. when someone clicks on the "read-only" text box it checks the function which has been set to false by the button and force the focus elsewhere.<BR><BR>&#060;script=javascript&#062;<BR >function leaveMeAlone() {<BR>document.form.button.setfocus<BR><BR>}<BR><BR >&#060;/script&#062;<BR><BR>&#060;INPUT TYPE=submit name=button onClick="leaveMeAlone()"&#062;

  3. #3
    Join Date
    Dec 1969

    Default Almost right...

    There is no such thing as "setfocus". Instead, you simply call the focus() method of some *other* that is *not* readonly. So the function looks something like this:<BR><BR>var isReadOnly = false;<BR>... and some other code can set that variable to true ...<BR><BR>function leaveMeAlone( )<BR>{<BR>&nbsp; &nbsp; if ( isReadOnly ) document.form.someNonReadOnlyField.focus( );<BR>}<BR><BR>The code is short enough that you don&#039;t even have to put it in a function, of course. Just write it directly into the onClick (or, for text fields, the onFocus) event handler. <BR><BR>Finally, you can&#039;t prevent a SUBMIT button from being clicked in this way, so use a TYPE=BUTTON instead and simply have it ignore the click if read only is set--that is, do something like<BR><BR>&#060;INPUT Type=Button Name="PseudoSubmit" Value="Submit" onClick="if (! isReadOnly) this.form.submit();"&#062;<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts