I am trying to get either a dropdown or selection box(prefer the later, because of the possibility to choose multiple values at once) in a webform.
In this case i already got the dropdown working, based on measures.measurement_type. The second needs to be measures.measurement, filtered by the type selected in the first dropdown.
I can not seem to get this working. I tried googling, but without succes. Can anyone help me get on the right track?
I found solutions using Arrays, but no working solution using 1 database table.
using ruby 4.2
Thanks
There are two options for this.
Using AJAX calls. Like #Ronan said in his answer, you need to make an AJAX call on the selection of first drop down (on change method). In the rails action method, you can render a JS partial where you can set the filtered items for second drop down.
Another one is totally client side. Like render all the possible items of both drop downs to client side. Meaning both type and measurements as javascript array. Then when changing the type drop down, filter the measurements array using jQuery and populate in the second drop down.
You gotta use some ajax for doing that, can't see other way. When your measures.measurement_type changes, you send a request passing that measurement_type as param for your action. In that action, you retrieve the collection of measurements based on the measurement_type passed in the param, and then return that data to be handled on your success ajax callback. On that method, with some jquery you should populate the second input with the options returned.
This is some simpler explanation... you should take some look at a more complete article for understanding step-by-step. Would suggest this one, for example: https://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax. Good luck!
Related
My goal is very simple and I would guess it is a very common goal among web developers.
I am creating a Rails (5.1) application, and I simply want to use AJAX to get the value of a specific cell in a specific row of a specific table in my database (later I am going to use that value to highlight some text on the current page in the user's browser).
I have not been able to find any documentation online explaining how to do this. As I said, it seems like a basic task to ask of jquery and ajax, so I'm confused as to why I'm having so much trouble figuring it out.
For concreteness, say I have a table called 'animals', and I want to get the value of the column 'species' for the animal with 'id' = 99.
How can I construct an AJAX call to query the database for the value of 'species' for the 'animal' with 'id' = 99 .
Though some DBs provide a REST API, what we commonly do is define a route in the app to pull and return data from the DB.
So:
Add a route
Add a controller/action for that route
In that action, fetch the data from the DB and render it in your preferred format
On the client-side, make the AJAX call to that controller/action and do something with the response.
I have received data from json web service with RESTRequest component
but I do not know how I should display the returned data in a grid?
How can I use RESTResponseDataSetAdapter to improve this?
Try this - it took me about 15 minutes to get working
Open the RESTDemos in your Delphi install's Samples\Object Pascal\Database\RESTDemo
Drop a TStringGrid on the RHS of the the Delphi-Praxis tab (I chose this one because
the URI on the Fetch to DataSet produces a 404 error).
If necessary, make the non-visual controls on the form visible.
Dbl-click BindingList and use the QuickBindings to add a LinkGridToDataSource. Set its
DataSource to ClientDataSet and its GridControl to StringGrid1. Thus will cause DBSourceDB1 to be created'.
Set the Response property of RestReponseDataSetAdaptor to `RESTResponse'.
Compile, run and click the fetch list of forums button. You should see the StringGrid populates
from the contents of memo_ResponseData
That should show you that LiveBindings can work with a RESTReponse to populate a grid. The RESTDemos demo has a lot more things in it, but if this is your first experience of LiveBindings, you might want to backtrack and try setting up a simple test project which populates a TStringGrid and a few TEdits from a dataset of your own.
I am creating a program in VB.NET which uses an online MySQL database to retrieve certain data. I have now succeeded in connecting and getting some basic stuff out of it. Now, what I want to do is that when an user presses a button it has to update the list. What happens is that the stuff that is already in the database also gets resent and so the list just doubles himself, although it adds the new database value.
How can I make sure that it only adds new values to the list, instead of adding all values from the list again? I have read that you can use the Preserve keyword with arrays, though this isn't an array and neither have I figured out how to convert my data into an array.
Private Sub generateList()
DB.writeQuery("SELECT snacks.ID, snacks.naam, snacks.baktijd FROM snacks")
While DB.DR.Read
ListBox1.Items.Add(DB.DR.Item("naam"))
End While
DB.closeConnection()
End Sub
This is the piece of code I use to generate the list, I reuse this code to refresh the list. As you can see, it uses my own written MySQL class. I know it makes an connection so there is nothing wrong with that.
Any help would be appreciated.
What you will want to do is to clear the ListBox before you reload the list. You can do this like so:
ListBox1.Items.Clear()
Then when you reload the list, the items will not be duplicated.
Looks like you need to clear your listbox before adding the items.
ListBox1.Items.Clear()
Try this my friend:
If Not listBox1.Items.Contains(DB.DR.Item("naam")) Then
ListBox1.Items.Add(DB.DR.Item("naam"))
else
'this item already exists.
end if
i'm working in a symfony project and using sfPropelPager to show a paged list of elements.
The problem is that with a great amount of data to list (i.e. thousands of registers) it makes a query to the database for each page to show!!!! That means about 100 extra queries in my case, and that is unacceptable.
Showing some of my code: the function that returns the pager object
$pager = new sfPropelPager('MyTable',sfConfig::get('sfPropelPagerLines'));
$c = new Criteria();
$c->add('my_table_field',$value);
$c->addDescendingOrderByColumn('date');
$pager->setCriteria($c);
$pager->init();
return $pager;
So, please, if you know a way to get all the results with only one query, it would be a great solution for my problem. Otherwise i must implement that list with an ajax call for every page the user wants to see
Thank you very much for your time.
I'm not sure to get your problem but, anyway, avoid the use of Criteria. Try to make queries with the ModelCriteria API: http://www.propelorm.org/reference/model-criteria.html.
For each paginated page, a query to the database will be done, this is the standard behavior for all pagers I know. If it's related to related objects (assuming you want to display information from relations), you may want to create a query that links those objects before to paginate, that way you'll get one query per page for all your data to display.
Read this doc for instance: http://www.propelorm.org/documentation/03-basic-crud.html#query_termination_methods
At last i did'nt get a solution for the problem, i had to implement the list via AJAX call, calling to a function that returns the requested page, so at the load of the page, no query for this list is slowing the user experience.
Thank you anyway to help me :)
I have an HTML TABLE that displays my records from mySQL.
I need to edit various records (rows). Is it possible to click on a table row and edit the values in the row inside the HTML table?
I was wondering if there are any PHP scripts out there to guide me?
Yes, it's possible. While I am very convinced PHP is involved, Javascript is involved also.
I think you can have something like this:
1.Click once, javascript increases a counter variable
2. Click twice, javascript checks if var = 2 after increasing, resets counter, and changes innerHTML of the td to something like this:
form action ='yourphpscript.php' method = 'getorpost'>
.....What you want to change....
</form>
3. So then it sends your values to the PHP script, PHP script changes values in database, and you get redirected back to the main page. Or, better yet, use AJAX.
Hope this helped :)