Javascript disabling input fields

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.

Answers


Make sure your submit function returns false if you don't want the page to refresh. The code you're looking for is document.getElementById('insertIdOfTextFieldHere').style.readonly = "readonly";


Need Your Help

obj-c : iphone programming NSTimeInterval problem

objective-c time intervals

i got a problem with my time interval. I need to get the interval of two times in this format : HH:MM. If i enter : 15:35 and 16:35 it is ok, but when i do 20:30 to 01:30, it gives me like 18 hours