Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

In choices, there is also a option for "Others", if that clicks a textbox will appear and when un-checks that will disappear. Lets do the same with Javascript.

Put the following code on the header section


code:

function displayField(fieldID, display)
{
document.getElementById(fieldID).style.display = (display) ? 'inline' : 'none';

}



and the following in the body section.


code:

function displayField(fieldID, display)

<input name="checkbox_other" type="checkbox" class="text_background" id="checkbox_other" value="other" onclick="displayField('newClientLbl', this.checked)">
<label style="display:none" id="newClientLbl">

Enter Your Client Type: <input name="newClient" class="text_background" type="text">

Here is links of some good Javascript reference books.

Single Page Reference

1. Javascript Quick Reference

2. Javascript Cheat Sheet

Books


3. Javascript: The Defenitive guide

4. Javascript By Example

Once my client asked me to do a validation for a form in which contains many check boxes. The form can submit the data if and only if at most 'm' number of check boxes are clicked. I have written a javascript function for that, so that it can re-use.


code:




function checkboxValidate(cform,max)
{
+++for (var c=0,d=0,e; e=cform[d]; d++)
++++{

+++++if (e.type=='checkbox' && e.name.match(/^show\[\]$/) && e.checked)
+++++++c++;
++++}
+++if (c > max)
+++{
++++alert('You can only click m checkboxes ');

+++++return false;
++++}
+++return true;
}




the function checkboxValidate takes two arguments

a.
cform - the name of the form, in which contains the checkboxes
b.
max - the allowed maximum number of checks.

You can edit this function and can enable it for the use of at least m number of clicks, that I left to you.

Category

Followers

FeedCount

Latest Posts

thecoderinc

Subscribe Now