File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Javascript disabling input fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript disabling input fields" Watch "Javascript disabling input fields" New topic

Javascript disabling input fields

Satish Nair

Joined: Apr 04, 2012
Posts: 23
I am looking for a javascript function. which will disable the entered (filled) text field on submit. So when the user logs in back the filled text box has to remain disabled. I have tried a code, but here what happens is on clicking the sumbit the contents in the text field gets deleted.

function enableDisable(){
var disable = true;
var arglen = arguments.length;
var startIndex = 0;
var frm = document.example1;//change appropriate form name
if (arglen>0){
if (typeof arguments[0]=="boolean") {
if (arglen>1) startIndex=1;
for (var i=startIndex;i<arglen;i++){
obj = eval("frm."+arguments[i]);
if (typeof obj=="object"){
if (document.layers) {
if (disable){
obj.onfocus=new Function("this.blur()");
if (obj.type=="text") obj.onchange=new Function("this.value=this.defaultValue");
else {
obj.onfocus=new Function("return");
if (obj.type=="text") obj.onchange=new Function("return");
else obj.disabled=disable;
<form name="example1">

Text Field: <input type="text" name="text1">
<input type="submit" name="control1" onclick="enableDisable(this.submit,'text1','submit','select1')">


please do guide.
Wendy Gibbons

Joined: Oct 21, 2008
Posts: 1107

please carefully choose the forum your thread goes in. it is unlikey anyone going into the database forum to help people would be there to answer jsp questions.
So I moved it for you
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

First, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I would have added them to your post for you, but you did not indent the code so it would not have helped much. Please repost the code in a new reply using code tags, and with proper indentation.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Javascript disabling input fields
It's not a secret anymore!