I'm currently using Perl CGI to display some internal billing pages at work. I'm using JQuery as well to add a little 'spunk' to it if you will.
I'm looking to generate/display HTML based on drop down selection by the user. Now, I can handle this part no problem. I'm generating table rows/table data on click based on the selection made by the user.
I want to retrieve and display values stored in the database for the corresponding data im displaying on button click, and without refreshing the page of course.
Can someone point me in the right direction? Thanks in advance.
You'll want to use an AJAX request to get the data. So, for example, if you have a select with class 'ajax' and you want to display data based on the option selected, you can do something like:
$('.ajax').change(function(){
$.get({'url', { value: this.val() }, function(data){
// display the data with a .html() or .append() or something
});
});
Replace 'url' with the url of a page that queries the database using the value that you send it.
Related
I'm trying to build a way to update a user profile one question at a time.
Essentially I want a div on my page that displays a form that lets the user submit the most important information, say firstname. When that has been filled out (success on the form) I want to refresh that div and show the second most important form, for say lastname, or if that is already filled in then birthday and so on.
Much like linkedin prompts you to add one more piece to your profile.
How would you do it?
My first thought was to use elements. But I need to fetch existing profile data to populate the form and how would the element get that data, abusing requestAction is not an option.
So I guess I in that case need to call a controller action that determines which element should be rendered, renders it to a variable and submits that (response->body) in json to the js that updates the page. Seems a bit .. unclean but should work.
Then we have view cells. They seem ideal for the task until I want to call them via ajax. That is not possible right?
So how would you go about to build something like that?
A form that needs to have the ability to be prepopulated with data if there is any and then refreshed automagically to display the form for the next piece of info needed.
View cells can't really be used in AJAX requests. This is not what they thought for.
The best thing you could do, if you want to keep the cell, is to make sure you followed SoC properly and put all your business logic into the model layer.
Now have a separate controller and action that is reachable from the outside throught a request (a cell is not) and return the data as JSON from there using the same code.
You could try to instantiate the cell in the controller action as well and send it's output. But honestly, I think that's a pretty fugly way of doing it.
I have a Dojo Grid. Every row has a link to the formular, where the data can be changed. Now, when I click save and close (in the form) I want the grid to reload the displayed data. So far, I've managed to reload the data, but I always jump back to the start of the grid. But, e.g. if I'm at the end of the table, I want to reload just the last few entries.
My grid is connected to a JSONRest Store, so basically I just should know the range which is displayed right now... . How do I get the range?
If you have backed your grid by a store, you simply "put" the changed object to your store. The JsonRest store you are using will send the changes back to your server with a PUT request and the grid will pick up the changes and update the corresponding item.
When pressing save in your form, you would need to create a json representation of your form data (that matches the one used in the grid) and put this to the store:
require(["dojo/dom-form", ... ], function(domForm, ...) {
...
var updatedItem = domForm.toObject("yourFormId");
yourGridStore.put(updatedItem).then(function() {
console.log("put was successful");
});
...
}
I've managed to solve the problem without any put to the store. Here is the code:
grid._lastScrollTop=grid.scrollTop;
grid._refresh();
And here is the link where I've found the answer. It is the answer number 6.
Hi I'm not sure if i'm using the right words in the title, please correct me if not. I've been working for almost a month with kendo ui. It's really good.
Now my problem, i'm working with html, django and kendo. I'm getting information from a url in json format. I'm able to load the information in a Kendo Grid, with a boolean values column and a text column. In the boolean values column i've found a way to turn it into a checkbox input column with a field template and set its checked value according to the data i got from the url. The problem is that I can't manage to bind the checked value to the data in the grid's datasource, so when I click the save button to save the new information I get the same data I got from the url. Does anybody know how to do this or a simpler way to do it instead of mine? Thank you!
There is a code library project which covers almost the same scenario. You could use the same idea to update the underlying model which the Grid uses.
http://www.kendoui.com/code-library/mvc/grid/checkbox-column-and-incell-editing.aspx
I have a web page consisting of a dropdown menu. What i want is the contents of other dropdown menus present in the page must change according to what has been selected in the first dropdown box. For example if a dropdown consists of Degree as its element. If i select Degree element then another dropdown must show only degree courses. This must happen automatically without clicking any button. How can i achieve this?
I would make this a comment, but I do not have commenting abilities. You are going to want to use $.post with jquery and ajax to accomplish this: http://api.jquery.com/jQuery.post/ . Ajax with JQuery is not difficult to do.
You will want to use the onchange event of the first drop down to use a jquery ajax $.post call to post to the server, passing the selection from the drop down as a parameter. The page that it post's to should us GET to get the selected attribute from the drop down, and then retrieve ( from the database or where ever) the options that go into the second drop down, based on the parameter. The code should be written out to the page. The jquery ajax call has a way to get the response and let you define a custom function to be run once the post returns. The return should be what you had written out to the page, and then you can just update the second drop down list with the returned data inside this function.
I hope this helps!
HTML form has some text boxes and a drop down box.
Drop down has huge values, and takes lot of time to fetch from database.
So I want to load the page first and while the user fills the form (text boxes) I want to load the drop down box (without his knowledge :-) ).
But without any event trigger, how do I make call to database again ?
I am using JSF with RichFaces, Servlet.
The following code is not working
<h:selectOneMenu value="#{obj.selectedValue}">
<f:selectItems value="#{obj.allValues}" />
<a4j:support selfRendered="true" action="#{bean.action}"/>
</h:selectOneMenu>
Thanks,
+1 for using Ajax - but if you have a very large number of values,t hen you might want to consider using an auto completion dropdown - where the the user starts typing what they need and after they have typed a few characters, you kick off your ajax reqeuest and just load those requests that match.
have a look at "google suggest" if you want to see this in action
-Ace
As already mentioned you can use AJAX to load the dropdown items asynchronously, but I would suggest redesigning the form so that the huge dropdown is not required. Perhaps let the user search for the correct value on a previous or subsequent screen? Long dropdowns are not easy to use as they require lots of scrolling and it can be hard to find the correct value on a large list.
At the bottom of your page put the following:
<a4j:jsFunction name="yourJsFunction" action="#{bean.fetchSelectItems}"
reRender="yourDropdown" />
window.onload = yourJsFunction();
You will have to use AJAX. When the page loads display a empty select box. Then write some JavaScript that will call some URL on your server that will return the options for the select box. And when you get that just populate the select box with those values.
Be advised that your form will be useless to those without JavaScript.