User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,920 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,559 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 587 | Replies: 4 | Solved
Reply
Join Date: Dec 2007
Posts: 226
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX OmniX is offline Offline
Posting Whiz in Training

Help Selecting all input text fields

  #1  
Jan 4th, 2008
Im looking for a piece of code that can be used to select all input text fields and then disable and enable them at will.

I was trying to work off this:

text = document.getElementsByTagName("input");

THEN when required:

text.disable = true;
text.disable = false;

Thanks, Regards X.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 35
Reputation: mellamokb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
mellamokb mellamokb is offline Offline
Light Poster

Re: Selecting all input text fields

  #2  
Jan 4th, 2008
Im looking for a piece of code that can be used to select all input text fields and then disable and enable them at will.

Here is a javascript function that will enable or disable all input text fields:

function setInputTextEnabled(isEnabled)
{

    inputArray = document.getElementsByTagName("input");
    
    for (var index = 0; index < inputArray.length; index++)
        if (inputArray[index].type = 'text')
            inputArray[index].disabled = isEnabled;
        
}

You specify true or false for isEnabled depending on whether you want them all to be enabled or disabled. I've also checked that the type of input is 'text' as you said. If you want to affect all input's, remove the line that begins "if (inputArray...").

text = document.getElementsByTagName("input");

Note that the variable 'text' holds an array, not a single object, so you have to specify indices as I did in the code above in order to change individual properties, such as:

text = document.getElementsByTagName("input");
text[5].value = 'abcdef';

~ mellamokb
Reply With Quote  
Join Date: Dec 2007
Posts: 226
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX OmniX is offline Offline
Posting Whiz in Training

Re: Selecting all input text fields

  #3  
Jan 5th, 2008
mellamokb my hero!

ya i came up with similar code but it is not working, at the moment im trying to use a checkbox to implement the enable or disable ALL checkboxes but its not working =( Also any ideas on my other post on trying to stop a submit button from working? (idea was return false but no go still goes to next page) =(

Ill try figure something out, keep you posted.

ps: good heads up on the text array i overlook easy things sometimes =(
Last edited by OmniX : Jan 5th, 2008 at 12:23 am.
Reply With Quote  
Join Date: Jan 2008
Posts: 35
Reputation: mellamokb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
mellamokb mellamokb is offline Offline
Light Poster

Re: Selecting all input text fields

  #4  
Jan 5th, 2008
Here is full page source that works. I fixed a bug in the javascript I wrote, where I used a single equals where I should have used double equals for comparison:

<html>
    <head>
        <title>Test</title>
        <script type="text/javascript">
        <!--
    
            function setInputTextEnabled(isEnabled)
            {

                inputArray = document.getElementsByTagName("input");
                
                for (var index = 0; index < inputArray.length; index++)
                    if (inputArray[index].type == 'text')
                        inputArray[index].disabled = isEnabled;
                    
            }        
        
        // -->
        </script>
    </head>
    <body>
        <input id="Text1" type="text" value="123" /><br />
        <input id="Text2" type="text" value="123asffdd" /><br />
        <input id="Text3" type="text" value="12353" /><br />
        <input id="Text4" type="text" value="12weaf3" /><br />
        <input id="Text5" type="text" value="12asgd3" /><br />
        <input id="Text6" type="text" value="12asdf3" /><br />
        <input id="Text7" type="text" value="12awef3" /><br />
        <input id="Text8" type="radio" name="r1" value="12awef3" /><br />
        <input id="Text9" type="radio" name="r1" value="12awef3" /><br />
        <input id="Text10" type="checkbox" value="12awef3" /><br /><br />
        
        Change Text Enabled: <input id="Text11" type="checkbox" onclick="setInputTextEnabled(this.checked);" value="12awef3" />
    </body>
</html>

~ mellamokb
Reply With Quote  
Join Date: Dec 2007
Posts: 226
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX OmniX is offline Offline
Posting Whiz in Training

Re: Selecting all input text fields

  #5  
Jan 5th, 2008
~ mellamokb
Dont ask me what the problem was.
Ran your code worked perfectly, then ran mine and worked fine. Anyways beautiful work once again, you have helped me so much and gone that extra mile, THankyou =)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC