We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,154 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to disable and enable form?

HI i have many forms in my application..
when some one see any form so i want to show form as "Only readable form" means i want to use disable form..
when someone click edit button so my form should enable for editing..
how to do it? can anyone help me?
Regards..
Farhad

5
Contributors
4
Replies
3 Days
Discussion Span
3 Months Ago
Last Updated
5
Views
Farhad.idrees
Junior Poster
102 posts since Dec 2010
Reputation Points: 11
Solved Threads: 0
Skill Endorsements: 0

On a form, you will have many HTML input elements. These elements can have an attributed called 'disabled'. If you enable/disable this attribute via JavaScript or easier with the jQuery library, you can control that behavior.

For example, the following code produces a disabled input button of type 'submit'.

<input type="button" value="Submit" disabled/>

Using jQuery, you can remove this attribute as follows: $("input").removeAttr("disabled")

JorgeM
Industrious Poster
4,018 posts since Dec 2011
Reputation Points: 297
Solved Threads: 548
Skill Endorsements: 115
<input  type="text" name="name" id="name"  onkeyup="document.getElementById('box_submit').disabled = this.value=='' ? true : false;"/>
    <input id="box_submit" type="button" value="Continue" name="check" disabled=""/>

try this button is enable only when some-one input somthing in text box

arti18
Posting Whiz in Training
207 posts since Dec 2012
Reputation Points: 2
Solved Threads: 25
Skill Endorsements: 0

Try this

<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>

</head>
<body>
<form id="formElem">
<label for="txtName">Name</label>
<input type="text" name="txtName" />
<label for="txtAddress">Address</label>
<textarea name="txtAddress"></textarea>
</form>
<a href="#NOD" class="disableForm" >Disable Form</a>
<a href="#NOD" class="enableForm" >Enable Form</a>

<script type="text/javascript">
$(function(){
    $('.disableForm').click(function(){
        $('input, textarea').attr('disabled', true);
    });
    $('.enableForm').click(function(){
        $('input, textarea').attr('disabled', false);
    });
});
</script>

</body>
</html>
Bachov Varghese
Junior Poster
123 posts since Sep 2011
Reputation Points: 41
Solved Threads: 29
Skill Endorsements: 3

if youre using jquery

function set_status(){
    $('formname input').each(function() {
        if(this.disabled==true){
            this.disabled=false;
        }else{
            this.disabled=true;
        }
});
}

or native javascript

function set_status(){
        var len = document.former.elements.length;  //please be noted that former is the name of your form
        for(var x=0;x<len;x++){
            if(document.former.elements[x].disabled==true){
                document.former.elements[x].disabled=false;
            }else{
                document.former.elements[x].disabled=true;
            }
        }
    }
code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1028 seconds using 2.71MB