populating Database date on change of Select in Struts2 - mysql

I am trying to change the table data in JSP on change of ListBox.
When user select Organisation Name then, the table will be only display list of users belonged to that organisation.
I feel like the action class isn't being called from javascripts.
<script type="text/javascript">
function getOrganisationUsersList(value){
var submitUrl = "listUserByOrganisation.action?organisationId="+value;
$.ajax({
url:submiturl,
type: 'get',
beforeSend: function(){
$("#loading").show();
alert("parsed");
},
success: function(result){
if(result!=''){
$('.myTableWrapper').html(result);
} else {
alert(result);
}
}
});
}
</script>
Below is select tag which calls the javascript.
<s:select listKey="%{organisationId}" list="organisationList" listValue="%{organisationName}"onchange="getOrganisationUsersList(this.value)"/>
I populate all users at the start of the page.
so, to only display selected user for particular organisation, do I need to create another action class? I am now trying to use the same action. Help needed !!!
Thanks.

Related

Autofill form with existing form values

I am trying to get a form field to autofill with the same value as another field using Ninja Forms and Wordpress. I have looked at some solutions using JQuery but none of them seem to work. Please help me figure out what I am doing wrong.
Here is a link to the form: https://optionsqa.wpengine.com/test-page/
I want to get the content in "COPY THIS LINK" to automatically populate the field below.
This is the script I am trying:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.copy-link').on('change', function() {
jQuery('.favorite-link-field').val($(this).val());
});
});
</script>
jQuery solution (updated to include ninja form ready state, as per comments):
I prefer using the id over class since classes can be used multiple times. That being said:
This will update when #nf-field-10 or Favorites Link is changed.
jQuery(document).on( 'nfFormReady', function( e, layoutView ) {
jQuery('#nf-field-10').on('change', function() {
jQuery('#nf-field-10').val(jQuery('#nf-field-16').val());
});
});

Save car id into html

I working with Laravel, with blade views.
I have an array of cars. The user can choose one car from the list, each user can only show his list.
After selecting a car, a modal view appears into the same HTML for showing more information about the car.
If the user wants to remove the car, a post request is called, and HERE is the problem.
How can I pass to the modal, the id of the car that he selected? Because I need it for the post request if he wants to delete the car for example. May be save into variable.
I know how to pass parameter to the modal and then show it into "h3" or "inputs"but this id I can't show him, also he can't change it because he can modify it to remove another car from the list.
Thanks for help
I think i understand what you need, so you have a main controller
public function cars()
{
$cars = Cars::all();
return view('cars',compact('cars'))
}
Then what you can do if you a view single car or delete you can pass the model.
public function single(Cars $cars)
{
return view('single',compact('cars'))
}
Your routes willl look like this
Route::get('cars',['uses' => 'CarsController#cars','as' => 'cars.all']);
Route::get('cars/{cars}',['uses' => 'CarsController#single' => 'as' => 'cars.single']);
and your HTML will be
{{$car->name}}
Hope this helps?
If you was posting via Ajax you would do something like this.
#foreach($cars as $car)
<tr>
<td>{{$car->name}}</td>
<td><a class="view" href="#" data-id="{{$car->id}}">View</a></td>
</tr>
#endforeach
<script>
$('.view').click(function() {
var car = $(this);
var car_id = car.data('id');
$.ajax({
url: '/car/single'+car_id,
type: 'get',
success: function(data) {
$('#details').html(data);
}
});
});
</script>
Will use the same controller:
public function single(Cars $cars)
{
return $cars;
}

Can we send values to a form through a link?

I wanna send values to a Registration form via links. I want it to send different values depending on what link is used to access the page...
For example;
If a link called Add User is clicked I want a value like "User" sent as a parameter
If a link called Add Admin is clicked I want a value like "Admin" sent as a parameter
I also want the Parameter to be not seen on the url....
You can't have a link that includes parameters without the parameters being visible.
If it's just a question of aesthetics, you can always have the link point to the form and then have the form save that value in some sort of internal storage (sessions? a database? a cookie? whatever's appropriate in your situation) and then redirect to a URL that doesn't include the parameter.
Your other option is to use JavaScript and AJAX to have the link submit a form "behind the scenes", and then reload the page yourself using the results of that AJAX request.
Use simple jQuery ajax for pass the values. Add jquery library in header,
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url : "servletURL",
data : { field1: "admin", field2 : "user"}
type : "POST",
success: function (response) {
//your success code
},
error: function () {
//your error code
}
});
});
</script>

Can't populate data with binding

This is my first try to make a single page application with HTML5. I'm using jquery, knockout and sammy.
Code: http://codepaste.net/apdrme
The problem is that I don't know what I'm doing wrong. I know it is the following:
this.get("#/", function() {
this.personList(this.persons);
});
But how else can I populate the list?
You could populate your list as follows:
function ViewModel() {
this.personList = ko.observableArray([{"name":"Josh"}, {"name":"Barry"}, {"name":"Mike"}]);
};
[...]
ko.applyBindings(new ViewModel());
Pay attention to use ko.observableArray() at the declaration. So, you could also remove the argument and call this.personList([{"name":"Josh"}, {"name":"Barry"}, {"name":"Mike"}]) in your main Sammy route and fill the list with other values in another route.
Another mistake is that you have used the with-binding that is not necessary here. Check the documentation about it.
You would normally use jQuery and an ajax call to populate personList. personList should be an ko.observableArray.
this.personList = ko.observableArray();
this.get("#/", function() {
$.ajax({url:"/api/persons/", dataType: 'json', success:function(persons){
this.personList(persons);
}});
});

Click event not registering on second page

I'm using tablesorter and tablesorter.pager. Here is my code:
$(document).ready(function() {
$("#peopletable")
.tablesorter({ widthFixed: true, widgets: ['zebra'] })
.tablesorterFilter({ filterContainer: $("#people-filter-box"),
filterClearContainer: $("#people-filter-clear-button"),
filterColumns: [1, 2, 3],
filterCaseSensitive: false
})
.tablesorterPager({ container: $("#peoplepager") });
$("#peopletable tr.data").click(function() {
var personid = $(this).attr('id');
$.ajax({
type: "POST",
url: "/Search/GetDocumentsByPerson",
data: { "id": personid },
datatype: "json",
success: function(data) {
var results = eval(data);
$("#documentstable > tbody tr").remove();
$.each(results, function(key, item) {
$("#documentstable > tbody:last").append(html);
});
$("#documentstable").trigger("update");
}
});
});
});
Everything works great except when I click on the next page my button click event doesn't fire. Is this a known issue with jQuery tablesorter?
It's because the elements are updated, the ones you bound the click handler to are gone, you can use .live() to resolve this, change this:
$("#peopletable tr.data").click(function() {
To this:
$("#peopletable tr.data").live('click', function() {
Alternatively, if #peopletable isn't destroyed you can use .delegate(), like this:
$("#peopletable").delegate('tr.data', 'click', function() {
I have also faced the same kind of problem with tablesorterPager second page after using Jeditable (edit in place) plugin for some element in the tablesorterPager used table.
I have tried editing the data bind function in Jeditable as follows
original code
$(this).bind(settings.event, function(e) {
here settings.event equals to the event parameter which we are defining with options eg: click
modified code
$(this).live(settings.event, function(e) {
But.. I found the error with tablesorterPager within pages other than the first page is not because of the binding of element event.
when we are calling tablesorterPager to any table with many rows, only the first page rows of
the table is affected on the page load. so only the first page rows are called with Jeditable plugin. other rows in the other pages are not assigned with the plugin. because of this reason, the events in other pages than first page will not work.
to prevent above situation, we can add Jeditable plugin calling inside updatePageDisplay function.
eg:
function updatePageDisplay(c) {
$(".tablerowdata").each(function(){
$(this).editable("ajax/save.php", {
tooltip : "click to edit...",
data : {"selectid1":"selectval1","selectid2":"selectval2","selectid3":"selectval3"},
type : "select",
submit : "ok",
event : "click",
select : "true",
});
});
Creating a new element won't duplicate the event created with the click method wheras the live method does it.