Jump to content

chaging value of drop down menu on select


ashutoash

Recommended Posts

I am using jquery .change function to perform an operation when a month is selected from a drop down menu. The change works but I am unable to update the value of the drop down menu with the updated month. My drop down shows the starting value as default even on change. Can anyone help. Following is the code snippet that does change and then the drop down menu form.

 

$("#monthName").change(function()
{
	alert($("#monthName").val());
	if ($("#post").val() == 1)
	{
		$("#monthselect").submit();
	}
});

 

                   <form id="monthselect" action="<?=$_SERVER['PHP_SELF']?>" method="get">
                        <input id="post" type="hidden" name="post" value="1">
                        <label>SELECT MONTH</label>
                        <select id="monthName" name="monthName">
                        	                             
                                <option value="January">January</option>
                                <option value="February">February</option>
                                <option value="March">March</option>
                                <option value="April">April</option>
                                <option value="May">May</option>
                                <option value="June">June</option>
                                <option value="July">July</option>
                                <option value="August">August</option>
                                <option value="September">September</option>
                                <option value="October">October</option>
                                <option value="November">November</option>
                                <option value="December">December</option>

                        </select>
                    </form>

 

Even after the change, January shows up by default even if I select say June or July. I tried something like following but did not work.

 

$("#monthName option[value=" + $("#monthName").val() +"]").attr("selected","selected") ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.