I am trying to validate(if they have value) my 1st two dropdowns of my html . On click of button getURL I am validating if there are any selected values in dropdowns and if YES I would like to proceed to function getURL.
But soon after validation , the control is not stopping if there are no values in 2nd dropbox. Its going ahead and displaying the URL.
I would like to display URL only if there are values in 1st two dropdowns. But now with my below code I am getting alert:url soon after alert:select product version
Javascript:
function validate() {
var pname = document.getElementById("selProductName");
if(pname.selectedIndex == 0) {
alert('select product name');
}
var pversion = document.getElementById("selProductVersion");
if(pversion.selectedIndex == 0) {
alert('select product version');
return false;
}
return true;
}
function getURL() {
validate();
// I have code here to create desired URL
alert("url:" + url);
}
HTML:
Product Name:
<select id="selProductName" name="selProductName" onchange="changeProductName(this.value);">
<option>--Choose Product Name--</option>
</select>
<br>Product Version:
<select id="selProductVersion" name="selProductVersion" onchange="changeProductVersion(this.value);">
</select>
<br>File Name:
<select id="selFileName" name="selFileName"></select>
<br><button onclick="getURL()">Get URL</button>