Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Disable or lock textbox


Message #1 by "Enzo Zaragoza" <enzaux@g...> on Wed, 24 Oct 2001 20:32:14 +0800
Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William








$subst('Email.Unsub')



Message #2 by "Drew, Ron" <RDrew@B...> on Wed, 24 Oct 2001 09:07:02 -0400
2 Ways of doing this.....depending on how you want the presentation



1......

<form name="xxx" action="your.asp" method="POST">



<!--  First I show the key/date but do not allow changes to them...hide it

so it gets passed with the POST-->

<p>Key: <%=form_id%></p><input type="hidden" name="id" value="<%=form_id%>">

<p>Date: <%=form_indate%></p><input type="hidden" name="indate"

value="<%=form_indate%>"></p>



<!-- Now open up the fields that the user can change...-->

<p>Account:<input type="TEXT" name="inacct" size="07"

value="<%=form_inacct%>">



<p> <input type="SUBMIT" value="Change Record"> </p>

</form>



2........

Just put the key word Read-only

<input type="TEXT" name="inacct" size="07" value="<%=form_inacct%>"

read-only>

<!-- This prevents the user from changing the text in a field-->





-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...] 

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according to

data extracted from database. For each box I have onchange event handler to

call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus is

on the next text box, say box2. My code(in vbscript where x is the ordinal

number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is as

follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William
Message #3 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 24 Oct 2001 14:08:07 +0100
IE supports the Disabled propery, but this actually grays it out which is

not always desirable.  



<INPUT TYPE="checkbox" ID="chk1" ... DISABLED>



you can then turn this on and off dynamically



document.all.chk1.disabled = true/false



A more comprehensive solution for supporting more browsers would be to add

in an onclick event handler that changes the checked property back after its

clicked



<INPUT TYPE="checkbox" ...

ONCLICK="(this.checked)?this.checked=false:this.checked=true;">



turning this on and off is a bit trickier, but can be done - let us know if

you need more help



-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...]

Sent: 24 October 2001 13:32

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William
Message #4 by Sam Clohesy <sam@e...> on Wed, 24 Oct 2001 14:14:51 +0100
This will work, it is for a list box but you can do the same for a text box

as well





I am preety sure not in Netscape though...



<select name="cat" class="select200" disabled>			

<option value="38">First Thoughts</option>

<option value="36">Interviews</option>

<option value="37">Local Authorities</option>

</select>



-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...]

Sent: 24 October 2001 13:32

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William
Message #5 by "Coffey, Dana" <dcoffey@B...> on Wed, 24 Oct 2001 06:47:39 -0700
What I do in this case is make a "mock" textbox using a small table and

cell.



-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...]

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William
Message #6 by "Enzo Zaragoza" <enzaux@g...> on Wed, 24 Oct 2001 22:42:22 +0800

Thanks Ron, Alex and Coffey!  I thnk Ill just do put them on a table and 

only provide a textbox for those fields that is editable :) but if you 

still have better ways please tell me.  Thanks again!



Enzo

  ----- Original Message -----

  From: Alex Shiell, ITS, EC, SE

  To: ASP Web HowTo

  Sent: Wednesday, October 24, 2001 9:08 PM

  Subject: [asp_web_howto] RE: Disable or lock textbox





  IE supports the Disabled propery, but this actually grays it out which 

is

  not always desirable. 



  <INPUT TYPE=3D"checkbox" ID=3D"chk1" ... DISABLED>



  you can then turn this on and off dynamically



  document.all.chk1.disabled =3D true/false



  A more comprehensive solution for supporting more browsers would be to 

add

  in an onclick event handler that changes the checked property back 

after its

  clicked



  <INPUT TYPE=3D"checkbox" ...

  ONCLICK=3D"(this.checked)?this.checked=3Dfalse:this.checked=3Dtrue;">



  turning this on and off is a bit trickier, but can be done - let us 

know if

  you need more help



  -----Original Message-----

  From: Enzo Zaragoza [mailto:enzaux@g...]

  Sent: 24 October 2001 13:32

  To: ASP Web HowTo

  Subject: [asp_web_howto] Disable or lock textbox





  Greetings!!!

     I would like to ask how to disable or lock textbox so that the data 

in it

  will not be edited?  Does it require javascripting or ASP could handle 

that?

  If it uses javascript could you give me a sample javascript.  Thank 

you very

  much.



  Enzo





  ----- Original Message -----

  From: williams@s...

  To: ASP Web HowTo

  Sent: Wednesday, October 24, 2001 6:00 AM

  Subject: [asp_web_howto] focus on text box







  Hi,



  I have created an asp file which dynamically creates text boxes 

according

  to data extracted from database. For each box I have onchange event 

handler

  to call a subroutine to validate user input. So validation will be 

done

  whenever user finished input on one text box , say box1, and press 

tab.



  In the subroutine, in case the user input is invalid, I have problem 

to set

  back the focus on the input box and select the text . Everytime the 

focus

  is on the next text box, say box2. My code(in vbscript where x is the

  ordinal number within the elements array) is as folow:



  form1.elements(x).focus

  form1.elements(x).select



  I further tried to change the value of the input box (box1) in case of

  invalid input data . This time the value of the input box (box1) is 

changed

  to 'aaaa' but the focus is still on the next text box (box2). The code 

is

  as follow:



  form1.elements(x).value=3D"aaaa"

  form1.elements(x).focus

  form1.elements(x).select



  I further tried to click on other text box, say box6, after inputting

  invalid data in the box1. This time the focus is on box6.



  Please help.



  Thanks

  William









Message #7 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 24 Oct 2001 15:40:56 +0100
'readonly' is one word, it only applies to text input fields and textareas,

and it only works in IE



but it is nice because it doesn't grey out the field.



-----Original Message-----

From: Drew, Ron [mailto:RDrew@B...]

Sent: 24 October 2001 14:07

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Disable or lock textbox





2 Ways of doing this.....depending on how you want the presentation



1......

<form name="xxx" action="your.asp" method="POST">



<!--  First I show the key/date but do not allow changes to them...hide it

so it gets passed with the POST-->

<p>Key: <%=form_id%></p><input type="hidden" name="id" value="<%=form_id%>">

<p>Date: <%=form_indate%></p><input type="hidden" name="indate"

value="<%=form_indate%>"></p>



<!-- Now open up the fields that the user can change...-->

<p>Account:<input type="TEXT" name="inacct" size="07"

value="<%=form_inacct%>">



<p> <input type="SUBMIT" value="Change Record"> </p>

</form>



2........

Just put the key word Read-only

<input type="TEXT" name="inacct" size="07" value="<%=form_inacct%>"

read-only>

<!-- This prevents the user from changing the text in a field-->





-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...] 

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according to

data extracted from database. For each box I have onchange event handler to

call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus is

on the next text box, say box2. My code(in vbscript where x is the ordinal

number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is as

follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William



Message #8 by "Tim Morford" <tmorford@n...> on Wed, 24 Oct 2001 11:08:01 -0400
Hey you could use <input name=test onFocus="this.blur()" value="what ever

you want">

this will lock what ever you want it to.



Tim Morford



-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...]

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William



Message #9 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 24 Oct 2001 16:19:10 +0100
for check boxes this is only effective if you tab to it - if you click it

with the mouse then it will still check or clear the checkbox.  This is a

very effective solution for text input fields though.



-----Original Message-----

From: Tim Morford [mailto:tmorford@n...]

Sent: 24 October 2001 16:08

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Disable or lock textbox





Hey you could use <input name=test onFocus="this.blur()" value="what ever

you want">

this will lock what ever you want it to.



Tim Morford



-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...]

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo





----- Original Message -----

From: williams@s...

To: ASP Web HowTo

Sent: Wednesday, October 24, 2001 6:00 AM

Subject: [asp_web_howto] focus on text box







Hi,



I have created an asp file which dynamically creates text boxes according

to data extracted from database. For each box I have onchange event handler

to call a subroutine to validate user input. So validation will be done

whenever user finished input on one text box , say box1, and press tab.



In the subroutine, in case the user input is invalid, I have problem to set

back the focus on the input box and select the text . Everytime the focus

is on the next text box, say box2. My code(in vbscript where x is the

ordinal number within the elements array) is as folow:



form1.elements(x).focus

form1.elements(x).select



I further tried to change the value of the input box (box1) in case of

invalid input data . This time the value of the input box (box1) is changed

to 'aaaa' but the focus is still on the next text box (box2). The code is

as follow:



form1.elements(x).value="aaaa"

form1.elements(x).focus

form1.elements(x).select



I further tried to click on other text box, say box6, after inputting

invalid data in the box1. This time the focus is on box6.



Please help.



Thanks

William
Message #10 by "Enzo Zaragoza" <enzaux@g...> on Thu, 25 Oct 2001 00:24:12 +0800
thanks Tim, i think i'll be using your suggestion,  thanks for all those 

who helped me!!!



Enzo



  ----- Original Message -----

  From: Tim Morford

  To: ASP Web HowTo

  Sent: Wednesday, October 24, 2001 11:08 PM

  Subject: [asp_web_howto] RE: Disable or lock textbox





  Hey you could use <input name=3Dtest onFocus=3D"this.blur()" 

value=3D"what ever

  you want">

  this will lock what ever you want it to.



  Tim Morford



  -----Original Message-----

  From: Enzo Zaragoza [mailto:enzaux@g...]

  Sent: Wednesday, October 24, 2001 8:32 AM

  To: ASP Web HowTo

  Subject: [asp_web_howto] Disable or lock textbox





  Greetings!!!

     I would like to ask how to disable or lock textbox so that the data 

in it

  will not be edited?  Does it require javascripting or ASP could handle 

that?

  If it uses javascript could you give me a sample javascript.  Thank 

you very

  much.



  Enzo





  ----- Original Message -----

  From: williams@s...

  To: ASP Web HowTo

  Sent: Wednesday, October 24, 2001 6:00 AM

  Subject: [asp_web_howto] focus on text box







  Hi,



  I have created an asp file which dynamically creates text boxes 

according

  to data extracted from database. For each box I have onchange event 

handler

  to call a subroutine to validate user input. So validation will be 

done

  whenever user finished input on one text box , say box1, and press 

tab.



  In the subroutine, in case the user input is invalid, I have problem 

to set

  back the focus on the input box and select the text . Everytime the 

focus

  is on the next text box, say box2. My code(in vbscript where x is the

  ordinal number within the elements array) is as folow:



  form1.elements(x).focus

  form1.elements(x).select



  I further tried to change the value of the input box (box1) in case of

  invalid input data . This time the value of the input box (box1) is 

changed

  to 'aaaa' but the focus is still on the next text box (box2). The code 

is

  as follow:



  form1.elements(x).value=3D"aaaa"

  form1.elements(x).focus

  form1.elements(x).select



  I further tried to click on other text box, say box6, after inputting

  invalid data in the box1. This time the focus is on box6.



  Please help.



  Thanks

  William



Message #11 by "Drew, Ron" <RDrew@B...> on Wed, 24 Oct 2001 17:51:26 -0400
My mistake..sorry..should have tested it before typing the reply



-----Original Message-----

From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...] 

Sent: Wednesday, October 24, 2001 10:41 AM

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Disable or lock textbox





'readonly' is one word, it only applies to text input fields and textareas,

and it only works in IE



but it is nice because it doesn't grey out the field.



-----Original Message-----

From: Drew, Ron [mailto:RDrew@B...]

Sent: 24 October 2001 14:07

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Disable or lock textbox





2 Ways of doing this.....depending on how you want the presentation



1......

<form name="xxx" action="your.asp" method="POST">



<!--  First I show the key/date but do not allow changes to them...hide it

so it gets passed with the POST-->

<p>Key: <%=form_id%></p><input type="hidden" name="id" value="<%=form_id%>">

<p>Date: <%=form_indate%></p><input type="hidden" name="indate"

value="<%=form_indate%>"></p>



<!-- Now open up the fields that the user can change...--> <p>Account:<input

type="TEXT" name="inacct" size="07" value="<%=form_inacct%>">



<p> <input type="SUBMIT" value="Change Record"> </p>

</form>



2........

Just put the key word Read-only

<input type="TEXT" name="inacct" size="07" value="<%=form_inacct%>"

read-only>

<!-- This prevents the user from changing the text in a field-->





-----Original Message-----

From: Enzo Zaragoza [mailto:enzaux@g...] 

Sent: Wednesday, October 24, 2001 8:32 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Disable or lock textbox





Greetings!!!

   I would like to ask how to disable or lock textbox so that the data in it

will not be edited?  Does it require javascripting or ASP could handle that?

If it uses javascript could you give me a sample javascript.  Thank you very

much.



Enzo



Message #12 by Dennis <dennist@g...> on Mon, 29 Oct 2001 11:37:24 +0530
Enzo,

        Use this. It should do u good.



onfocus="javascript:this.blur();"



eg.

<input type="text" name="sometext" onfocus="javascript:this.blur();">



regards,

Dennis.


  Return to Index