Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function validateField() {

            var Inp = document.getElementsByTagName("input");
            var s = document.getElementsByTagName("select");
            for (var i = 0; i < Inp.length + s.length; i++) {
                if (Inp[i].getAttribute("isvalid") == "In") {
                    if (Inp[i].value == "") {
                        alert("Pls enter value");
                    }
                }
                else {
                    if (s[i].value == "Select") {
                        alert("Pls select city");
                    }
                }
            }
        }
Posted
Comments
Mohibur Rashid 15-Jul-15 3:15am    
loop for s and loop for Inp should be different. Don't you think?
how many select object with City information do you have? if just one, why don't you give it a id. and the one object with s=document.getElementById("select_id"); value would be s.value; simple as it is.
Atmesh 15-Jul-15 3:18am    
Ok thank you

1 solution

C#
var selected_index = oForm.elements["country"].selectedIndex;

if(selected_index > 0)
{
   var selected_option_value = oForm.elements["country"].options[selected_index].value;
   var selected_option_text = oForm.elements["country"].options[selected_index].text;
}
else
{
   alert('Please select a country from the drop down list');
}
 
Share this answer
 
Comments
Mohibur Rashid 15-Jul-15 3:13am    
Not a good answer.
Lakhan Anjana 15-Jul-15 3:37am    
you can post some thing good example.....instead of making nonsense comments.


at least i tried
Lakhan Anjana 15-Jul-15 6:51am    
you can post some thing good example.....instead of making nonsense comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900