Solved

onSubmit check the checkbox value

Posted on 2013-01-28
3
348 Views
Last Modified: 2013-01-30
I am new to javascript, how to write on submit, check that Src and Dst are never checked at the same time; otherwise alert.

<FORM METHOD=POST>

       <INPUT TYPE=\"checkbox\" NAME=\"top\" value=\"Eve\" $eventIdChk >Evening<br>
       <INPUT TYPE=\"checkbox\" NAME=\"top\" value=\"Src\" $srcIpChk >Source<br>
       <INPUT TYPE=\"checkbox\" NAME=\"top\" value=\"Dst\" $dstIpChk >Destination<br>

<INPUT TYPE=\"submit\" NAME=\"SetIt\" VALUE=\"SetIt\">

</FORM>
0
Comment
Question by:rgbcof
[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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38829456
Test page : http://jsfiddle.net/efpTm/1/
<script type="text/javascript">
window.onload = function() {

document.getElementsByTagName("form")[0].onsubmit = function() {
     var Src_Is_Checked = document.getElementsByName("top")[1].checked;
     var Dst_Is_Checked = document.getElementsByName("top")[2].checked;
     if( Src_Is_Checked && Dst_Is_Checked ) {
          alert("please check source OR destination");
          return false;
     }
     return true;
}

}
</script>
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 38829459
0
 

Author Closing Comment

by:rgbcof
ID: 38838314
Works great.
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to refresh a page from a sub domain in ajax ? 34 49
Worldmap 1 28
Debugging Html 8 32
replacing inline javascript with jquery 4 46
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 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