Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<script type="text/javascript">
    function getCombo1(sel)
  {
        var value = sel.options[sel.selectedIndex].value;
        $("#test").load("test.aspx?test=" + value);
      
    }
    

</script>

</head>
<body>
    
    
<select id="combo1" onchange="getCombo1(this)">
  <option value="ka">Karnataka</option>
  <option value="tn">Tamilnadu</option>
   <option value="ap">Andrapradesh</option>
  <option value="mh">Maharashtra</option>
</select>

  <pre id="test">


</body>
it will display the output in p tag
but i want it to b displayed in this 
<select id="Select1">
        <option></option>
    </select>
Posted
Updated 12-May-15 21:14pm
v2
Comments
Kornfeld Eliyahu Peter 13-May-15 2:57am    
What load is? Your method? Do some return(value); inside it!
(Or it is jQuery load method used in the wrong way?)
Sergey Alexandrovich Kryukov 13-May-15 3:00am    
What does it mean, "name variable"? What's the problem?
"$.name" means the property "name" of the object "$".
In jQuery, "$" is the function object, the factory method, and it has properties which are also functions, $.*(...)...
—SA
kiran gowda8 13-May-15 3:23am    
understood the problem??
Sergey Alexandrovich Kryukov 13-May-15 9:53am    
Who are you talking to?
—SA
Mohibur Rashid 13-May-15 4:10am    
Your question is not clear. please state clearly, what do you want and why its not working.

1 solution

This is not exactly "combo box"; this is HTML select element. By "display", you may mean selecting the item (option element) depending on some value you

Of course, you cannot use jQuery .load here. Please see what it does:
https://api.jquery.com/load[^].

It places some HTML in the element. This is not what you want. You want to remove selected attribute from one option element and either add this attribute to some other (or maybe the same) element, or none of them, in case there is no match.

The implementations of these operations are explained here; please see top answer to the question: http://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery[^].

Instead of .load, you need to just extract the value from service. Use general-purpose jQuery Ajax: http://api.jquery.com/jquery.ajax[^].

That's all. As you can see, this is considerably more tricky than .load, but nothing too hard.

—SA
 
Share this answer
 
Comments
kiran gowda8 14-May-15 1:48am    
thank you soo much Sergey Alexandrovich Kryukov..!!
Sergey Alexandrovich Kryukov 14-May-15 10:21am    
You are very welcome.
Good luck, call again.
—SA

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