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") ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.