?
Solved

Java Script: fire a function when Check Box value = Yes

Posted on 2011-03-09
8
Medium Priority
?
421 Views
Last Modified: 2012-05-11
Dear all,

  I created a Java Script function to validate input fields of a Form.  Since the form is long, instead of validate the form on Sumit, I'd like to have the page validate the input fields when a user checks one of the Check Box on the form.  Since check box changes value when clicked and unclicked, how do I make the page validates the form when the Check Box is Checked?

<html>
<head>
<script>

  function validateForm()

    { bluh bluh bluh... }

</script>
</head>


<body>

<form>

bluh..
bluh..

<input type="checkbox" name="chkbox_filled" value="Yes"> Please Validate this Section

</form>
</body>  
</html>
0
Comment
Question by:cuconsortium
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:vsudip
ID: 35091931
0
 
LVL 8

Expert Comment

by:vsudip
ID: 35091949
u can also refer below code....
Source: http://www.java2s.com/Tutorial/JavaScript/0200__Form/Checkboxclick.htm
<html>
    <form name="orderForm">
      <input type="checkbox" name="door4" onClick="alert('door4')">4 doors<br>
      <input type="checkbox" name="door2" onClick="displayNote()">2 doors<hr>
      Step 2:
      <input type="button" value="Submit Order" name="orderButton" onClick="alert('submitted')">
    </form>
    <script language="JavaScript">
    <!--
    function displayNote(){
      alert("Have you considered the 4-door version?");
      document.orderForm.door4.click();
    }
    -->
    </script>
    </html>

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35091955
I would recommend using jQuery library for that:
http://docs.jquery.com/Plugins/validation
does most of the work you want, for you.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 35092722
here is what I would do
Notice the (this) and (this.form)
<html>
<head>
<script>

  function validateForm(theForm) { // pass the form to the function

    bluh bluh bluh...
    return false; // cancel submission

    bluh bluh bluh...

    return true; // allow the submission
  }

</script>
</head>


<body>

<form onsubmit="return validateForm(this)">

bluh..
bluh..

<input type="checkbox" name="chkbox_filled" value="Yes" onClick="if (this.checked) validateForm(this.form)"> Please Validate this Section

</form>
</body>  
</html>

Open in new window

0
 

Author Comment

by:cuconsortium
ID: 35386257
This question is still active.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35387190
What does that mean.

Can you use what I posted? If not why not?
0
 

Author Comment

by:cuconsortium
ID: 35388240
I was just been traveling.  now, I'm back and am able to get back to this for the following 2 weeks for sure! sorry for the delay.
0
 

Author Comment

by:cuconsortium
ID: 35708019
Thank you all your patient~~
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question