Sunday, 15 June 2014

jquery - How to set an select value by Javascript when user sets another select value? -


I have two selected boxes when the user sets the second value of a selected box, then the value of a value How can selection be made?

"tasktype" name = "task_type" & gt; & Lt; Option value = "1" selected = "selected" & gt; Station 1 & lt; / Option & gt; & Lt; Option value = "2" & gt; Station 2 & lt; / Options & gt; & Lt; Option value = "3" & gt; Station 3 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Select ID = "Percent" name = "percent_food" & gt; & Lt; Option value = "0" selected = "selected" & gt; 0% & lt; / Options & gt; & Lt; Option value = "25" & gt; 25% & lt; / Options & gt; & Lt; Option value = "50" & gt; 50% & lt; / Options & gt; & Lt; Option value = "75" & gt; 75% & lt; / Options & gt; & Lt; Option value = "100" & gt; 100% & lt; / Options & gt; & Lt; / Select & gt;

For example, when the user sets the Setup to Set 2, the percentage will automatically be set to 75.

You probably want something like this; If you change the first selection, you can test the values ​​and set another:

< Div class = "snippet-code">
  $ ('#tasktip'). Change (function () {if (this.value == 1) Val ("50");}});  
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Select ID = "WorkType" name = "Task_type" & gt; & Lt; Option value = "1" selected = "selected" & gt; Station 1 & lt; / Option & gt; & Lt; Option value = "2" & gt; Station 2 & lt; / Options & gt; & Lt; Option value = "3" & gt; Station 3 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Select ID = "Percent" name = "percent_food" & gt; & Lt; Option value = "0" selected = "selected" & gt; 0% & lt; / Options & gt; & Lt; Option value = "25" & gt; 25% & lt; / Options & gt; & Lt; Option value = "50" & gt; 50% & lt; / Options & gt; & Lt; Option value = "75" & gt; 75% & lt; / Options & gt; & Lt; Option value = "100" & gt; 100% & lt; / Options & gt; & Lt; / Select & gt;  


No comments:

Post a Comment