?
Solved

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

Posted on 2011-03-09
8
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

752 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