Question: validate select tag items in javascript

Ads

 
 
 

Share on Google+Share on Google+

Cirrus
validate select tag items in javascript
1 Answer(s)      4 years and 5 months ago
Posted in : JavaScript Questions

Hi,

How to validate addition of two numbers from two different <select> tag items in JavaScript..?

Thanks in advance.

Ads
View Answers

December 7, 2012 at 3:27 PM


Here is an example that validates HTML select tag and find the addition of two numbers selected from the select tag.

<html>
        <script language = "Javascript">
         function validate(){
            if(document.form.n1.selectedIndex==""){
            alert ( "Please select first number!" );
            return false;  
           }
           if(document.form.n2.selectedIndex==""){
            alert ( "Please select second number!" );
            return false;  
           }
           var v1=document.form.n1.value;
           var v2=document.form.n2.value;
           var sum=parseInt(v1)+parseInt(v2);
           alert("Sum of two numbers: "+sum);
            return true;
          }
        </script>
        <form name="form" method="post" onSubmit="return validate()">
        <pre>
        Select Number1    <select name="n1">
                          <option value="Select">Select</option>
                          <option value="10">10</option>
                          <option value="20">20</option>
                          <option value="30">30</option>
                          <option value="40">40</option>
                          <option value="50">50</option>
                          </select>
        Select Number2    <select name="n2">
                          <option value="Select">Select</option>
                          <option value="60">60</option>
                          <option value="70">70</option>
                          <option value="80">80</option>
                          <option value="90">90</option>
                          <option value="100">100</option>
                          </select>

                          <input type="submit" name="Submit" value="Submit">
        </pre>
        </form>
</html>

Ads









Related Tutorials/Questions & Answers:
validate select tag items in javascript
validate select tag items in javascript  Hi, How to validate addition of two numbers from two different <select> tag items in JavaScript..? Thanks in advance
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
Advertisements
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
JavaScript validate select tag
JavaScript validate select tag In this tutorial, you will learn how to validate html select tag. Here, we have used two select tags to select numbers...="return validate()"> <pre> Select Number1 <select name
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
JavaScript regex validate Telephone no.
JavaScript regex validate Telephone no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var phone = document.getElementById("phone").value
javascript regex validate url
javascript regex validate url  How to validate URL in regex Javascript   <html> <head> <title>Url validation using regex</title> <script type="text/javascript"> function validate
struts2 select tag multiple
struts2 select tag multiple  struts2 select tag multiple
JavaScript regex validate Mobile no.
JavaScript regex validate Mobile no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var mobile = document.getElementById("mobile").value
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
javascript regex validate currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation using regex</title> <script type="text/javascript"> function
The select tag
In this section, you will learn about the select tag of Spring form tag library
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript   <SCRIPT> function validateDate(dtControl) { var input = document.getElementById(dtControl) var validformat=/^\d{1,2}\/\d
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
About Select tag
About Select tag  hello Sir I am using select tag in jsp page and i want to change the background color of label which I have given to the select... in select tag please give me the solution my code as follows : <s
about select tag
about select tag  Hi, i have a doubt regarding the usage of select tag,that is,suppose i am having two dropdown boxes,based on the selection of one dropdown item another dropdown item will be displayed without interacting
Select Box Validation in JavaScript
Select Box Validation in JavaScript In this section we will discuss about select box validation in JavaScript. Select box allows you to create drop down list and option tag inside the select tag is for available option in the list
javascript regex validate Special character
javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
nested select tag
nested select tag  My requirement is as follows suppose combobox to select country whenever i select a country it will show corresponding states...="javascript" type="text/javascript"> var xmlHttp var xmlHttp
Select Tag (Form Tag) Example
Select Tag (Form Tag) Example       In this section, we are going to describe the select tag. The select tag is a UI tag that is used to render an HTML input tag of type select. Add
JavaScript getElementById select
JavaScript getElementById select...; We can use document.getElementById() over the <select> tag... here to use getElementById with select by using a very simple example
JSF selectItems Tag
JSF selectItems Tag          This tag is used to add a set of items to the nearest enclosing parent (select one or select many) component. This tag can be used
JavaScript remove method
;select> tag by using the method remove() of the JavaScript. Syntax... the select tag element's reference. Description of code : To illustrate the use... a dropdown list by using <select> tag and by default it consists of four items
select tag in Struts2 to handle Enums - Struts
select tag in Struts2 to handle Enums  I have an java enum in my object. I am trying to set its values from struts2 select tag. I tried with "#list... to handle enums in struts2 select tag ?   Hi friend, Code to solve
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
JSF selectManyMenu Tag
will be discussed. This is used to select more than one items from a set of options... in different browsers. In Internet Explorer browser user can select the items by scrolling...="select one or more items">   <f:selectItem id="si1" itemLabel
How to add another option to the select tag using struts2 tag - Struts
How to add another option to the select tag using struts2 tag  Hi, How to add another option to select tag using tag. My scenario is : If the logged in user is admin then drop down should contain the normal list
JavaScript Comment Tag
JavaScript Comment Tag  How to write comment in JavaScript
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads