I created the dynamic dropdown list by dependency.i.e populating a dropdown by selecting the list of the other dropdown. below is the complete code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function dynamicdropdown(listindex)
{
document.getElementById("subcategory").length = 0;
switch (listindex)
{
case "Php" :
document.getElementById("subcategory").options[0]=new Option("Please select framework","");
document.getElementById("subcategory").options[1]=new Option("Cakephp","Cakephp");
document.getElementById("subcategory").options[2]=new Option("Wordpress","Wordpress");
document.getElementById("subcategory").options[3]=new Option("Codeigniter","Codeigniter");
document.getElementById("subcategory").options[4]=new Option("Joomla","Joomla");
document.getElementById("subcategory").options[5]=new Option("Magento","Magento");
break;
case "Javascript" :
document.getElementById("subcategory").options[0]=new Option("Please select framework","");
document.getElementById("subcategory").options[1]=new Option("D-Jango","D-Jango");
document.getElementById("subcategory").options[2]=new Option("Angular","Angular");
document.getElementById("subcategory").options[3]=new Option("Prototype","Prototype");
document.getElementById("subcategory").options[4]=new Option("jQuery","jQuery");
document.getElementById("subcategory").options[5]=new Option("Backbone","Backbone");
break;
}
return true;
}
</script>
</head>
<title>Dynamic Drop Down List</title>
<body>
<div class="category_div" id="category_div">Please specify language:
<select name="category" class="required-entry" id="category" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
<option value="">Select Language</option>
<option value="Php">Php</option>
<option value="Javascript">Javascript</option>
</select>
</div>
<div class="sub_category_div" id="sub_category_div">Please select framework:
<script type="text/javascript" language="JavaScript">
document.write('<select name="subcategory" id="subcategory"><option value="">Please select framework</option></select>')
</script>
<noscript>
<select name="subcategory" id="subcategory" >
<option value="">Please select framework</option>
</select>
</noscript>
</div>
</body>
Now i want to get the dropdowns to be on hover instead of onclick. and want to apply redirecting links to the sub dropdown options. Kindly help me how can i do this. thank you
selects are not built for hover. just don't use a select but a custom element.
I don't wanna take away the time you could invest trying to dispatch custom events and setting the .size attribute.
but just using a div and :hover seams easier to me.
Jason Knight maybe you know something :) I'm not a as experienced as you are.
Uhm, I'm not sure I follow the question -- but unless I'm GREATLY mistaken this is possibly something I wouldn't even have JavaScript involved in unless I REALLY needed IE8/earlier support.
The presence of document.write is a bit of a wonk (much like innerHTML you shouldn't be doing that anymore, this isn't 1998), getElementById is slow so you should only be doing that ONCE and storing the result, directly populating options can be problematic...
Likewise this is 2018, we haven't said lang="JavaScript" since Netscape 4 went the way of the dodo, type="text/javascript" went away nearly eight years ago, and you've got the outdated outmoded XML style charset meta instead of the modern one.
... and of course you have no graceful degradation option.
I'd fake the first "select" as APPEARING like one but containing radio buttons instead, so that adjacent sibling could select the correct sub-menu from sibling level selects. Would probably also help if you bothered having proper LABEL for those form elements.
I'm heading to bed soon, but when I'm bright eyed and bushy tailed I'll take a closer look. The big trick be it scripted or using HTML+CSS to do the heavy lifting is going to be your desired hovers WITHOUT telling touch to go f** itself.