reload a select list on button click not reloading the whole page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Susmita swasti
    New Member
    • Jan 2013
    • 3

    reload a select list on button click not reloading the whole page

    i just want to refresh a select list on button click .Dont want to reload the page.
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    Any introductory AJAX tutorial will tell you how to do that. If you have any issues I can help. What is the problem you are currently facing?

    Comment

    • Susmita swasti
      New Member
      • Jan 2013
      • 3

      #3
      Actually I have 2 <select> tag.
      i.e.
      Code:
      <select id="id1"  multiple class="chznselect"  >
        <option value="volvo"  >Volvo</option>
        <option value="saab" >Saab</option>
      </select>
      <select id="id2"  multiple class="chznselect"  onchange="">
        <option value="opel"  >Opel</option>
        <option value="audi">Audi</option>
      </select>
      my requirement is dat if I am selecting "volvo" value from 1st drop down box then 2nd drop down box will get refreshed with "audi" value selected by default.i.e. we have to dynamically assign Selected="Selec ted" for <option value="opel" >Opel</option>..
      plz help me ....u can use jQuery or Ajax ..
      Last edited by acoder; Jan 7 '13, 11:32 PM. Reason: Please use [code] tags when posting code

      Comment

      • Anas Mosaad
        New Member
        • Jan 2013
        • 185

        #4
        It seems to me that you don't need to interact with the server. You have everything on your page. You just need the mapping logic in your JS.

        Simply, onchange of the first list, check the value and select the equivalent option of the second select list - For example, to select opel using JQuery:
        Code:
        $("#id1").change(function() {
        	$("#id1 option:selected").each(function () {
        		alert("volvo" == $(this).val());
               	if("volvo" == $(this).val()) 
                 	$('#id2 option[value="opel"]').attr("selected", true);
               })
        });

        Comment

        • Susmita swasti
          New Member
          • Jan 2013
          • 3

          #5
          oopsss i tried ur code. but its not working...
          can u suggest me any other way..

          the code u hv provided change the attribute value but the second select list is not gettting refreshed..

          Comment

          • Anas Mosaad
            New Member
            • Jan 2013
            • 185

            #6
            What do u actually mean by getting refreshed. You need to deselect all?
            This snippet clear all selection:
            Code:
            $("#id2 option:selected").each(function(){
              $(this).removeAttr("selected");
            });

            Comment

            Working...