News
* IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. *** 
  Jan 3 2015 10:32PM     John
  5 Comments    6491 Views  
Validating the HTML control is a very important task in any application development.Now this page shows you how to validate the dropdown using java script.
JavaScript

<script type="text/javascript">
        function ddlValidate() {
            var e = document.getElementById("ddlView");
            var optionSelIndex = e.options[e.selectedIndex].value;
            var optionSelectedText = e.options[e.selectedIndex].text;
            if (optionSelIndex == 0) {
                alert("Please select a Course");
            }
            else {
                alert("Success !! You have selected Course : " + optionSelectedText); ;
            }
        }
    </script>

HTML

<html>
<body>
    <div>
        <span>Select the course : </span>
        <select id="ddlView">
            <option value="0">Select</option>
            <option value="1">Java Script</option>
            <option value="2">CSS</option>
            <option value="3">JQuery</option>
            <option value="3">HTML</option>
            <option value="3">C#</option>
        </select>
    </div>
    <br >
    <input type="button" class="btn" value="Submit" id="btnSubmit" onclick="ddlValidate();" />
</body>
</html>

CSS

<style type="text/css">
        .btn
        {
            line-height: 2.0;
            border-radius: 4px;
            border: none;
            font-size: 14px;
            cursor: pointer;
            color: #fff;
            background-color: #00a9da;
            border-color: #0094bf;
        }

</style>

Demo
You can see live demo from clicking the below Submit button.
Select the course :

Hi, This is John.I hope this page will helps you to validate dropdown using Javascript.Thanks.
BackToTop
Comments


parthtank1426
Nov 14 2018 4:38AM
how did u did this.
i want to know how to apply java-script externally.
how to link in html file and hoe to start writting in java-script file.


please give ans . thanks.your regards.
PARTH TANK
Barath Kumar
Dec 20 2018 11:10PM
Hi Parthtank, Right click on the project and create new java script file and start writing your own js code. And then just drag and drop from solution explore to actual page with in head tag. Thanks
Barath Kumar
Dec 21 2018 11:21AM
This is the actual syntax to include Java script file in to your html page
Barath Kumar
Dec 21 2018 11:22AM
Barath Kumar
Dec 21 2018 11:23AM

 
Search
Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Oct 29 2018 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Oct 28 2018 12:09PM Posted By Pranav
Google URL Shortener in C#
Oct 20 2018 12:09PM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Oct 5 2018 12:09PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Sep 26 2018 12:09PM Posted By John
Gridview custom CSS in ASP.Net
Sep 14 2018 12:09PM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Sep 10 2018 12:09PM Posted By Micheal
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: