This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Javascript disabling input fields  RSS feed

Satish Nair
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66187
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!