*
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
Author

Javascript disabling input fields

Satish Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 23
Team,
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.

<html>
<head>
<script>
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") {
disable=arguments[0];
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;
}
}
}
}
</script>
</head>
<body>
<form name="example1">


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

</form>
</body>
</html>

please do guide.
Wendy Gibbons
Bartender

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
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript disabling input fields
 
Similar Threads
jsf -javascript
making the textbox readonly
Cross browser issues
Submit Methods pulling same data
Assinging JavaScript variable as a textbox id