I have created a driven database drop down menu on my website. It sends the selected value by the user to the database to be checked and returns a specific item.
Everything works perfectly now but I'm trying to pre select the first value so that the user will have the first option as default and can add it to cart directly and they also can choose a different size. So far, I tried 'selected' inside the option in the drop down but it doesn't do anything but displays the value when the page loads.
One last thing to mention, I'm using Ajax function to submit selected value and return result from the database.
I can think of two ways for this.
When the page is requested, make a call to your DB in your server-side code to store that value beforehand.
Use javascript's onload event to select the value as a part of a client-side script. You can use this answer as reference.
Related
I have three select2 lists next to each other, first independent, second dependent on first, third dependent on second (cascading lists), that works as expected when I normally populate them by selecting some options. I have created a dynamic action that fills these items with values that I calculate when I click a button, but after the click, only the first select2 have selected value. The second and third value remains empty. When I check the session, all items have value in them. It appears that when I click the button that for a millisecond list are filled but after that values disappear. So my question is, how do I transfer values from server-side to client-side. I tried to refresh items, I have played with jQuery without success, also I have tried to separate dynamic action to set values separately but nothing worked. Values populate correctly so that is not the problem. Please help
Thank you in advance for your answer.
Is lazy loading checked for the select2 that are subject to this behaviour (Item -> Setting -> Lazy loading)? If so try unchecking it
I can either:
-Get the information using AJAX, creating a request every time I click on the dropdown.
-Populate the form passing the information to div like this:
#foreach($items as $item)
<div id="name_{{$item->id}}" value="{{$item->name}}"></div>
<div id="date_{{$item->id}}" value="{{$item->date}}"></div>
...
#endforeach
And then setting the value of the form with javascript, making a single request that extracts all the information and passing it to the site.
I have already done both, but I would like to know which one would be the most performant.
The answer is both, but depends on the case.
For instance if you use the ajax method and the dropdown box is never pressed is better than the passing the values.
If the dropdown box is hit once or more than once, the second method will be better. But you will have also a downside: you'll not get the newest version of the dropdown box information from where ever you get it.
Hi I am working on DOJO website and I need to get the dropdown selected value without redirecting to another page using DOJO script or Plain javascript(No jquery, because dojo website not supporting Jquery).
Here is my scenerio
View account
View payment
address change
FAQ
You want the value selected from a drop down box but the act of selecting the value in the first place causes a redirect? You mean the values are coded as links? If so then you need to find the code where the value is used as a link and write some condition to get the value rather than let the click redirect.
If you just want the currently selected value then you need to find the same code, where it was processed as a link, and set a variable there that you can use for your purposes.
Currenty I am using checkboxes to select more than one value in a form. So when creating a new post I can select all the categories it falls into. But the cat list is getting longer and is becoming a bit unmanagable.
I like how wordpress adds tags to each post via ajax. Wordpress has a text input field with autocomplete, you just start typing and then if it's already there (in the db) then it'll show and get adding to a list dynamically. If it's not found in the list then it gets inserted on form submit.
How can I achieve this or similar so that I don't have to use x amount of checkboxes?
Check out this jQuery library. It works on multi selects instead of checkboxes, but the logic and result is exactly what you need.
http://harvesthq.github.io/chosen/
(not affiliated, I've just used it a few times)
One option would be to make use a library such as jquery-autocomplete
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
This makes use of AJAX based functionality and will give you the ability to tweak it based on values stored in a database table. You can make a simple check function that, in the case the value can not be found, the user will have the option to simply press add and insert it into said library.
The rest is jsut a matter of styling and design.
I have an MVC3 application in Visual Studio 2010.
I have a view with several dropdowns that do javascript calls to populate dropdowns based on the selected value, some of which are disabled initially.
That all works great with the initial state of nothing. If I however pass routevalues to the dropdowns from a redirect to this action, I do get the value set correctly but it's not enabled like it should be on the dropdown for example and when I post the form, the ones that are greyed out are not passed back on the form.
How can I correct this?
Disabled form fields do not get POSTed. Have the value of each dropdown in a separate hidden field so that on from POST it is received on the server.
#Html.HiddenFor(x=>x.SomeID_1)
or
<%:Html.HiddenFor(x=>x.SomeID_1)%>
Another solution is to make them readonly but that way you dont get to edit them in the edit view