Web Design and Development Forums

form element disable script

This is a discussion on "form element disable script" within the JavaScript Forum section. This forum, and the thread "form element disable script are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 20th, 2008, 22:05   #1 (permalink)
New Member
 
Join Date: Jan 2008
Location: sydney
Posts: 7
form element disable script

Hi,

Im working on a form that is generated by a database query with Coldfusion.

I have a few issues with Javascript as i am relatively new to it.

my form is

would anyone be able to show me how to i can make it so when the checkbox is checked the radio button and textarea become disabled ?

My form elements are named "Name" + ID of the database record at at any time can be up to 50 records on one screen.

I only want to disable the form elements that are numbered the same as the checkbox that is selected.

IE = if delete1 is checked then i need textarea1 and radio1 disabled.

This is probably a very simple task but right now it is absolutely beyond me...

my form is below


HTML: Select all
<form action="" method="">

<textarea name="Textarea1" cols="40" rows="5"></textarea>

<input type="radio" name="radio1" value="show">

<input type="Checkbox" name="Delete1" value="123">

</form>
thenamenoonehastaken is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 09:39   #2 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: form element disable script

Step 1: Give your element IDs so that you can work with them via javascript
Step 2: Attach an "onchange" event to checkbox
Step 3: Use the value of "this.checked" to find out whether the checkbox is on/off
Step 4: Use that value to enable / disable the other elements

RESULT:
Code: Select all
<form action="" method="">
 <textarea name="Textarea1" id="Textarea1" cols="40" rows="5"></textarea>
 <input type="radio" name="radio1" id="radio1" value="show">
 <input type="Checkbox" name="Delete1" id="Delete1" onchange="
  document.getElementById('Textarea1').disabled = this.checked;
  document.getElementById('radio1').disabled = this.checked;
 " value="123">
</form>
ALTERNATIVE:
If you're starting up, I suggest you familiarize yourself with a library that takes care of browser compatibility for you. It can be very frustrating having to deal with these issues as an experienced developer - even more infuriating if you're a beginner.

Step 1: Give your element IDs so that you can work with them via javascript
Step 2: Get jQuery
Step 3: Use this code
Code: Select all
<form action="" method="">
 <textarea name="Textarea1" id="Textarea1" cols="40" rows="5"></textarea>
 <input type="radio" name="radio1" id="radio1" value="show">
 <input type="Checkbox" name="Delete1" id="Delete1" value="123">
</form>
<script language="javascript">
$(function(){
 $('#Delete1').change(function(){
  $('#Textarea1, #radio1').attr('disabled', this.checked);
 });
});
</script>
Techie note:
I'm sorry if I seem to be pushing everyone towards jQuery, but with a few years of experience, countless nights and cups of coffee under my belt, I think jQuery is the easiest way to introduce a beginner to jQuery - taking away the worries of cross browser compatibility.
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help please with PHP Form script mkidd PHP Forum 2 Jun 19th, 2007 10:27
Form Element has no properties when querying antonyx JavaScript Forum 13 Aug 25th, 2006 14:06
asp script to show element if 2 recordset are both empty? therese ASP Forum 4 Dec 1st, 2005 10:24
Disable ALL form buttons paqman JavaScript Forum 1 Feb 18th, 2005 14:00
XHTML Block Element in an Inline Element gohankid77 HTML Forum 6 Jul 27th, 2004 10:15



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 19:17.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59