Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i have two drop down boxes when i am selecting the category value in the first drop down box automatically/Dynamically the sub-category values had displayed in the second drop down box.Now i want to display the all sub-category values in the second drop down box in the div..so please help any one..

XML
<html>
<head>
<title>example</title>
<style>
#header{
        background-color:#c3dfef;
       }
#footer
{
            background-color:#ccecd8;
            margin:5px;
            display: block;
            clear: both;
 }
#sidebar-left
{
                background-color:#D0D0D0 ;
                float: left;
                width:250px;
                height:530px;
}

#content
{
                background-color:#ccdff0;
                height:530px;
}
div{
  padding:10px;
  border:solid 1px black;
}
.button2:hover {
        text-decoration: none;
        background: #007ead;
        background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
        background: -moz-linear-gradient(top,  #0095cc,  #00678e);
    }
</style>
<body>

 <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>

 <script>
jQuery(document).ready(function()
{
    jQuery.ajax(
    {
        type: 'GET',
        url: 'Youtube_category.php',
        dataType: 'JSON',
        success:function(data)
        {
                    for(i=0;i

<script>
jQuery(document).ready(function()
{
    jQuery('#parentCategory').change(function()
        {
        jQuery("#subCategory").load("subCategory.php?choice="+jQuery("#parentCategory").val());
    });
});
</script>


<script>
function showDiv() {

                       document.getElementById('sidebar-left').style.display = "block";
                       var index = document.getElementById('subCategory').selectedIndex;
                       var selectedText = document.getElementById('subCategory').options[index].innerHTML;
                       document.getElementById('sidebar-left').innerHTML = selectedText;

                    }
</script>

<form id="form1">
<div id="header" >

    <select id="parentCategory" value="parentCategory" class="button2" name="category">
        <option selected="selected" name="category" value="selected">--Select category--</option>
    </select>
    <select id="subCategory"  class="button2" name="subCategory">
        <option selected="selected" name="subCategory" value="selected">--Select subCategory--</option>

    </select>

<input type="button" name="answer" value="Go" class="button2"  önclick="showDiv()" />

 </div>



<div id="sidebar-left" ></div>

<div id="content"> content </div>
<div id="footer"> footer </div>
</div>
</head>
</form>
</body>
</html>

this is the code i had done..iam geeting only the selected valu in the div but i want all values in the dropdown
Posted
v2
Comments
Not clear. You are already populating the second dropdown.
Narendra Naidu89 17-Feb-14 5:37am    
i have already the second dropdown..now i want to display that values in the second dropdown into the div
So, what is the issue. What have you tried?
Narendra Naidu89 17-Feb-14 6:28am    
<html>
<head>
<title>example</title>
<style>
#header{
background-color:#c3dfef;
}
#footer
{
background-color:#ccecd8;
margin:5px;
display: block;
clear: both;
}
#sidebar-left
{
background-color:#D0D0D0 ;
float: left;
width:250px;
height:530px;
}

#content
{
background-color:#ccdff0;
height:530px;
}
div{
padding:10px;
border:solid 1px black;
}
.button2:hover {
text-decoration: none;
background: #007ead;
background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
background: -moz-linear-gradient(top, #0095cc, #00678e);
}
</style>
<body>

<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>

<script>
jQuery(document).ready(function()
{
jQuery.ajax(
{
type: 'GET',
url: 'Youtube_category.php',
dataType: 'JSON',
success:function(data)
{
for(i=0;i<jquery(data).length;i++)
{
="" $('#parentcategory').append('&lt;option="" value="+ data[i].categoryName+">' + data[i].categoryName + '</option>');
}
}
});
});
</script>

<script>
jQuery(document).ready(function()
{
jQuery('#parentCategory').change(function()
{
jQuery("#subCategory").load("subCategory.php?choice="+jQuery("#parentCategory").val());
});
});
</script>


<script>
function showDiv() {

document.getElementById('sidebar-left').style.display = "block";
var index = document.getElementById('subCategory').selectedIndex;
var selectedText = document.getElementById('subCategory').options[index].innerHTML;
document.getElementById('sidebar-left').innerHTML = selectedText;

}
</script>

<form id="form1">
<div id="header" >

<select id="parentCategory" value="parentCategory" class="button2" name="category">
<option selected="selected" name="category" value="selected">--Select category--</option>
</select>
<select id="subCategory" class="button2" name="subCategory">
<option selected="selected" name="subCategory" value="selected">--Select subCategory--</option>

</select>

<input type="button" name="answer" value="Go" class="button2" önclick="showDiv()" />

</div>



<div id="sidebar-left" ></div>

<div id="content"> content </div>
<div id="footer"> footer </div>
</div>
</head>
</form>
</body>
</html>
this is the code i had done..iam geeting only the selected valu in the div but i want all values in the dropdown
EZW 18-Feb-14 3:26am    
I think he wants to populate the DIV based on what is selected from the second dropdown.

1 solution

Please check the Demo - [Issue] Show all values of DropDownList in Div[^].
It does what you need.

Just modify the showDiv() function like...
JavaScript
function showDiv() {
    var ddlSubCategory = document.getElementById('subCategory');

    for (i = 0; i < ddlSubCategory.options.length; i++) {
        document.getElementById('sidebar-left').innerHTML += ddlSubCategory.options[i].value + "<br/>";
    }
}
 
Share this answer
 
v2

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