Hi I want to make multiple selection a href.
Please help me to how to do it.
Thanks for your help.
If you ask for the below mentioned answer:
<select onchange="location.href=this.value;">
<option value="http://some_url/1.jpg">1.jpg</option>
<option value="http://otherurl/2.jpg">2.jpg</option>
</select>
Related
I've got a select menu that I've created with Thymeleaf. I need the menu to have no default choice. Usually this is done with a disabled extra option, and that I have done too. Now, the issue is that I just cannot get the selected attribute to render into the resulting HTML. This appears to break IE, which then defaults to the first non-disabled option. This is what I've got:
<select th:field="*{serviceName}" required="required" >
<option th:selected="true" th:disabled="true" th:value="NOT_SELECTED" th:text="'Pick one'"></option>
<option th:each="entry : ${form.services}"
th:value="${entry.key}" th:text="${entry.value}">
</option>
</select>
and it renders like this:
<select required="required" id="serviceTechnicalName" name="serviceTechnicalName">
<option disabled="disabled" value="NOT_SELECTED">Pick one</option>
<option value="SERVICE1">Service One</option>
<option value="SERVICE2">Service Two</option>
</select>
What am I doing wrong? I've been fiddling with different combinations of these different options for at least an hour already, it shouldn't be this difficult...
FWIW, this appears to be a duplicate question, but the answers there aren't doing it for me. There also isn't an accepted answer there.
Apparently, when using th:field it does not work. Look at this post.
However, I do not think you have to use th:selected as there is no processing in the server.
Have you tryied something like:
<select th:field="*{serviceName}" required="required" >
<option value="" selected="selected">Selecione</option>
<option th:each="entry : ${form.services}"
th:value="${entry.key}" th:text="${entry.value}">
</option>
</select>
Well, the forum post that Kimy82 suggested goes deep down into some Java configuration hole, so the solution did not appeal to me.
I then upgraded my Spring Boot from 1.3.3-RELEASE to 1.4.0-RELEASE. Then I spent a while trying to upgrade Thymeleaf from version 2 to version 3, but apparently could not get all the dependencies and excluded transitive dependencies right.
So in the end I did this:
<script type="text/javascript">
window.addEventListener('load', function () {
document.getElementById('serviceTechnicalName').value='NOT_SELECTED';
});
</script>
Now, it's not the answer I was looking for, but it does the job...
I am trying to do select an option in a select element. I tried the following code. But it does not work.
<select>
<option value="1" #(ViewBag.dt.Rows[0][1].ToString())=="1"? selected>A</option>
<option value="2" #(ViewBag.dt.Rows[0][1].ToString())=="2"? selected>B</option>
<option value="3" #(ViewBag.dt.Rows[0][1].ToString())=="3"? selected>C</option>
</select>
Any help?
Thank you.
Your conditional operators appear incomplete (invalid code).
Did you mean:
<option value="1" #(ViewBag.dt.Rows[0][1].ToString() == "1" ? "selected" : "")>A</option>
I would normally suggest switching to #Html.RadioButtonFor but that will not handle a two-dimensional array references. Are you display multiple items in a loop? You may be able to simplify the whole thing (please show the rest of your page/code).
I have a dropdown select menu rendered via this code
#Html.DropDownListFor(m => m.OwnedItemId, Model.Plans, "Select a plan type", new {#class = "selectMenu", id="addPlanSelectmenu"})
In the view it looks something like this:
<select class="selectMenu" data-val="true" data-val-number="The field OwnedItemId must be a number." id="addPlanSelectmenu" name="OwnedItemId" aria-disabled="false" style="display: none;">
<option value="">Select a plan type</option>
<option value="143863">RetirementSaving (143863)</option>
<option value="143876">BankAccount (143876)</option>
<option value="143913">RetirementSaving (143913)</option>
<option value="143929">RetirementSaving (143929)</option>
<option value="144030">BankAccount (144030)</option>
...
</select>
I would like to go to the default option after submitting but I can't make it work. So far I have tried quite a few things, like the one proposed in this answer, using
$('#addPlanSelectmenu').selectmenu("value", "");
Funny enough to my understanding if I do something like this
$('#addPlanSelectmenu').selectmenu("value", null); //Or an unexisting value
it goes back to the last option of the list.
Any idea?
Thanks
Edit: I forgot to mention that I guess a clean way is just adding a value to the default text, but I don't even know if it's possible with these helpers
Edit 2:
I eventually made it work using this answer
Try this code:
$('#addPlanSelectmenu').selectmenu("index", 0);
Similar as resetting - the only solution working to me:
$('#resetButton').click(function() {
$("#Service").selectmenu('destroy');
$("#Service").prop('selectedIndex',0);
$("#Service").selectmenu();
})';
A little late to the party, however considering that all the other answers are either incorrect or incomplete, I'll throw in my 2 cents!
All you need to do is
$('.selectmenu').val(""); // your default option's value
$('.selectmenu').selectmenu("refresh");
Well in MVC #Html.DropDownListFor this worked for me using jquery.
if ('#resetButton').click(function(){
$("#id").select2('data', null);
}
I use symfony 1.4.12 with Zend Lucene. And I make custom search, I have field like category, country...I create module and I have MysearchSucess.php and there I write hardcode, like :
<select name="ads_country" id="ads_country">
<option value="AF">Afghanistan</option>
<option value="AX">Ă…land Islands</option>
<option value="AL">Albania</option>
</select>
etc... But there are in symfony nice widget like sfWidgetFormI18nChoiceCountry;
Or for examle, if user add category, I will need to add new category in code manualy... Is it possible to use widgets in my case? how to organize it right without hardcode?
Thank you!
Ok, I read this and all ok!
Is there a good way to make an HTML dropdown read only. Using disabled attribute of select seems to work, but the value is not posted.
<select disabled="disabled">
I have a complex page with lots of javascript and ajax. Some actions in the form cause to drop down to be read only some actions let user decide the value.
Edit: Is there a better way other than using a hidden input?
If you do not want user to pick an option, how is this different from read-only input type="text"?
<select name="selectbox" disabled="disabled">
<option>option 1</option>
<option selected="selected">option 2</option>
<option>option 3</option>
</select>
Correct me if I am wrong, but if an option is selected, the value is sent