How to make input type text uneditable

Results 1 to 6 of 6

Thread: How to make input type text uneditable

  1. #1
    Join Date
    Dec 1969
    Posts
    90

    Default How to make input type text uneditable

    Can someone tell me how to make input type text uneditable or unchange. I use input type="text" in my form in order to pick up information from the user. After that I display that info. again in another form using the same input type but this time I give the value="&#060;%=Server.HTMLEncode(cs.Fields("Code") )%&#062;" for instance. Of course user still can change the value inside. How to make that input type uneditable by the user where user just can see but cannot change. If possible I want to display the second form like the first form by not using Response.Write (Code). The example of my code is:<BR><BR>&#060;input type="text" name="Code" size="45" maxlength="128" value="&#060;%=Server.HTMLEncode(cs.Fields("Code") )%&#062;"&#062;

  2. #2
    Kasper Guest

    Default RE: How to make input type text uneditable

    I know there is another solution to this problem, but if you need a quick solution try this:<BR><BR>Insert an onBlur event to your input, and have that event set the contents to the original cs.Fields("Code")<BR><BR>This way the users can still edit the contents, but when they leave the text box, or submit your form, the data will be reset.<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    376

    Default Set READONLY

    &#060;input type=&#039;text&#039; name=&#039;thing&#039; value=&#039;stuff&#039; READONLY&#062;

  4. #4
    Join Date
    Dec 1969
    Posts
    90

    Default RE: How to make input type text uneditable

    Thanks Casper but How to set onBlur event. I am new in HTML and ASP. Can you give me the example??


  5. #5
    Join Date
    Dec 1969
    Posts
    331

    Default RE: How to make input type text uneditable

    There are two ways to do this. <BR><BR>1. Put the READONLY or DISABLED attributes into the INPUT tag. The problem with this is that it only works with Internet Explorer. <BR><BR>&#060;INPUT TYPE="text" NAME="test" VALUE="test text" READONLY&#062;<BR>or <BR>&#060;INPUT TYPE="text" NAME="test" VALUE="test text" DISABLED&#062;<BR><BR>2. Use JavaScript to prevent the text element from getting focus. This works for both IE and Netscape but only if JavaScript is turned on.<BR><BR>&#060;INPUT TYPE="text" NAME="test" VALUE="test text" onfocus="blur();"&#062;<BR><BR><BR>You might want to look at another option entirley. Since the data has already been submitted, you can store it on the server and then write it back to the page as plain text instead in form fields. If you don&#039;t want to store it on the server then write it back to the page as plain text for display and as hidden fields for resubmittal. This is the most foolproof way to do it.

  6. #6
    Vijay Guest

    Default RE: How to make input type text uneditable

    READONLY does not work in netscape4.x....<BR>&#060;INPUT Type=text Value="..." onFocus="this.blur()"&#062;<BR><BR>This will not allow user to set the focus on the text field.<BR><BR>But why are you putting the output into a text box (value="&#060;%=Server.HTMLEncode(cs.Fields("Code" ))%&#062;") when you do not want user to change it?<BR><BR>You can simply display it like &#060;TD&#062;&#060;%=cs.Fields("Code")%&#062;&#06 0;/TD&#062; inside a table & show it wherever you want on th html page.

Posting Permissions

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


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies