Chovy’s Blog

Disabling Form Elements with Javascript

Thu, May 5, 2005 — Category: Personal

Here’s something I’m a proud of, I had to figure out a way to disable form elements which were children of a table row class, or rather all table row classes not currently selected from the dropdown menu:
<select name="cat" id="cat" onChange="showHide(this.value);">

<option value="res" >Resumes</option> <option value="ggg" >Gigs</option> <option value="eee" >Events</option>

</select>

<table> <tr id="res" style="display: none;"> […]

Here’s something I’m a proud of, I had to figure out a way to disable form elements which were children of a table row class, or rather all table row classes not currently selected from the dropdown menu:

<select name="cat" id="cat" onChange="showHide(this.value);">

 <option value="res" >Resumes</option> <option value="ggg" >Gigs</option> <option value="eee" >Events</option>

</select>

<table> <tr id="res" style="display: none;">  <td><img src="/images/spacer.gif" width="10" height="1" border="0"></td>

  <td>Resumes Options:</td>  <td>None Available</td> </tr>

        <tr id="ggg" style="display: none;">

                <td><img src="/images/spacer.gif" width="10" height="1" border="0"></td>                <td>Gigs Options:</td>

                <td>None Available</td>        </tr> <tr id="eee" style="display: none;">                <td><img src="/images/spacer.gif" width="10" height="1" border="0"></td>

                <td>Events Options:</td>                <td>None Available</td>        </tr></table>

Consider the following javascript for looping through the form elements:

//usage: onSubmit=”findOptions(this.cat.value)”

function findOptions(selectedId){ //populate array with possible options from “cat” var selectObj = document.getElementById(”cat”); var options = new Array(selectObj.length);

 for (var i = 0; i < selectObj.length; i++) {  options[i] = selectObj[i].value; }

 //check unselected options and get their nodes for (var i = 0; i < options.length; i++) {  if (options[i] != selectedId)  {   var disableId = options[i];   //alert(disableId);   getFormNodes(disableId);  } }}

function getFormNodes(disableId){ //get the form nodes from the id to disable //alert(disableId); var obj = document.getElementById(disableId); var inputTags = obj.getElementsByTagName(”input”); var selectTags = obj.getElementsByTagName(”select”);

 disableFormNodes(inputTags); disableFormNodes(selectTags);}

function disableFormNodes(formTags){ //disable each form node for (var i = 0; i < formTags.length; i++) {  var myNode = formTags[i];  myNode.disabled = true; }}
  • Post Disabling Form Elements with Javascript to del.icio.us
  • Post Disabling Form Elements with Javascript to digg
  • Post Disabling Form Elements with Javascript to Furl
  • Add Disabling Form Elements with Javascript to YahooMyWeb
  • Simpify!
  • Post Disabling Form Elements with Javascript to shadows
  • Post Disabling Form Elements with Javascript to Spurl
  • Post Disabling Form Elements with Javascript to BuddyMarks
  • Submit Disabling Form Elements with Javascript to Slashdot

2 Comments »

Trackback by adult video tv

October 20, 2007 @ 7:37 am

adult video tv…

Not much on my mind worth mentioning. I guess it doesn’t bother me. I’ve just been letting everything pass me by , but eh. That’s how it is. More or less nothing seems worth doing. …

Comment by ratna

April 10, 2008 @ 12:38 am

hi
i am working on APEX application in Oracle.my project is on timesheet management for the employee. if i select project as a leave,the whole row should be disable,so that i cannot enter the timesheet when i am on leave for a particular date. can i get the solution for this one.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

 
Keyword Advertisers:
SEO Directory SEO Links Free Link Directory Shopping Submission Directory Gardening Tips Political Forum Search Engine Optimization Search Engine Marketing Audio Video Directory SEO Forum Web Development Blog Organic SEO Wiki Web Development Consulting

Learn more about purchasing keyword text link ads on this site.