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.

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>









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">
struts2 select tag multiple
struts2 select tag multiple  struts2 select tag multiple
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
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 currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation using regex</title> <script type="text/javascript"> function
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
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
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
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
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 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">
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
JavaScript Comment Tag
JavaScript Comment Tag  How to write comment in JavaScript
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 : ADS..._object holds the select tag element's reference. Description of code : To illustrate... the element.selectedIndex item from the select tag option list. Here is the full
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
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...="#{TableBean.perInfoAll}" title="select one or more items">   <f:selectItem id="si1
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
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
JSF selectManyCheckbox Tag
JSF selectManyCheckbox Tag      This section is to describe you selectManyCheckbox tag of JSF. It is used to provide the user to select many items from a list of options. The user can
Select tag to fetch data from oracle database
Select tag to fetch data from oracle database  I created a select box having more than one menus in the select box such as regnno, address and name of a student and when regnno is selected from the drop down list by a user
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am..., but i am not able to use thin in tag of html
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am..., but i am not able to use this in tag of html
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in image tag but i am... image, but i am not able to use this in img tag of html
javascript script tag fields - Java Beginners
javascript script tag fields  hi all, i wanted to know what is meaning of type property in javascript script tag? In most cases we write type... of tag specifies the MIME type of a script. Javascript is the default scripting
How to give value for select in HTML dynamically using javascript
How to give value for select in HTML dynamically using javascript  hi. Consider the situation i am having 2 select options called degree and department. if i select a degree the departments corresponding to that degree only
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect....") return false; } } return true } function validate(){ var
we want to send requiest to server by html select tag - JSP-Servlet
we want to send requiest to server by html select tag  how we can send requiest to server using html select tag. and pass the value also  Hi Request Information In JSP Request Method
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered... and editing my html to call my functions to validate the user entered data...;title>Subscription Form</title> <script type="text/javascript">
dynamic generation of html:select tag from textbox value
dynamic generation of html:select tag from textbox value  Hi, I am a newbie to java and struts. In my application, I have a requirement like when i give some input in a textbox and click on a add link. It should be added
dynamic generation of html:select tag from textbox value
dynamic generation of html:select tag from textbox value  Hi, I am a newbie to java and struts. In my application, I have a requirement like when i give some input in a textbox and click on a add link. It should be added
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot apply date greater than 31/03 of particular year. So, if the user apply the date
how to get the value of a label field of option tag in javascript?
how to get the value of a label field of option tag in javascript?  example <select> <option label="2" value="A">A<...;/select> can i get the label value in javascript
Tomahawk selectManyCheckbox tag
; It is used to provide the user to select many items from a list of options. The user can select one or more options. This supports two layouts "...Tomahawk selectManyCheckbox tag  
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Display items in table
Display items in table  I have a listbox which has some items in it and a button. I select some items and click the button. They are displayed in a table. I want these items to be displayed in the table to be unique...i.e. if I
JavaScript - JavaScript Tutorial
how to immediately put JavaScript to validate forms, calculate values, work... is JSP using JavaScript I this example we will show you how to validate... where if user select any technology and press.   JavaScript

Ads