Remember selected option after redirect - php

Basicly, I have a <select> with a few options, when selected, it loads a jQuery dataTables table with content, in that table are options to edit/delete that content.
When a user deletes this content, or edits, it's redirected back to the first page, having to select the category again.
How would I set it so, that the <select> is auto selected, and the dataTable also loaded after an redirect?
My project is in PHP, so I can track what category it 'came from'

To auto select the category from your categories:
$(document).ready(function () {
$("#categories").val('<?php echo $selected_category;?>');
});
Assuming you have the $selected_category value (what category it came from).

Related

wordpress gravity form auto fill/select with current page title

I was wondering if it was possible to make a select dropdown inside a gravity form that can auto select a dropdown item according to the current page that it was loaded in.
For example:
I have 2 pages:
page A
page B
On every page I have the same form (form is made once).
And in that form I have a dropdown with 2 items (page A and page B)
But when I load page A I would like to make sure that the dropdown auto selects page A so that i can use conditional logic.
Ditto for page B.
How can i make sure that this will be possible in a short amount of time?
This is what i did so far:
app.js
e('.button[href^="#"]').on("click", e.proxy(this.openModal, this)),
this.prefillPopup();
prefillPopup: function () {
var i = parseInt(e("body").attr("class").split(" ")[2].replace("page-id-", ""));
e("#input_5_8").val(
{
427: "Personeelsfeest",
429: "Bedrijfsfeest",
431: "Walking en seated diners",
433: "Seminaries & Presentaties",
435: "Productlancering",
437: "Modeshows",
439: "Event op maat",
440: "Activiteiten",
}[i]
);
},
What i did is creating function that when the popup modal is opened/loaded the dropdown will be automatically filled with the data that I want it to be filled with.
The only thing is that it doesn't fill up with the content that I specify.
The dropdown needs to be filled with the desired titled related to the page ID that is being viewed in the browser at that time.

How to Insert a Record and load this record on select option without page refreshing in php using Ajax

I want to add product record under a product category. But if expected category not found on the select option I don't want cancel from this step I just want to add a category from this step. If I add the category then it will load select option without page refreshing.
Here I have to select option field
when I click on add category
After saving category it will load on the select option field
First use a different php page to call only options in select.
Then,
<script>
$("#id_of_submit_button").click(function(){
var category = $('#id_of_input').val();
$.ajax({
type: 'POST',
url: 'page_to_insert_category.php',
data: {category:category},
success:function(data){
//call the function which you used to get the options again
}
});
</script>
You will get the value of category in php page as
$_POST['category']
1.on click of submit button call an ajax
2. on same controller after save write logic for updated records in desc order and return in response updated array.
3. in success of ajax write logic for select last id record. ex. ($('#your_id [value=3]').attr('selected', 'true');)
4. trigger update on that select dropdown variable. ex. $('#mySelect').val('ab').trigger("updated");

How to do partial page refresh and get new data's or values each time

How to do partial page refresh and get new data's or values each time?
I have two tables .One table is to select the products and other is to display it and while selecting the products through a category .Each time it reloads and i lose the data's of previous category.So how to keep the second table without reloading until the user clicks on the submit button in the second table the table which is displaying ?How to achieve this!
You can do this with ajax technology. You need write something like:
$('#button_id').click( function() {
for (var i=0; i<numberRows; i++)
{
$('#id'+i).get('query.php?id='+i);
}
});
where for example "id7" is an id tag in this table, which corresponds with 7-th row and desired column in this row.
try to set javascript ajax action on submit button (not on checkboxes)
You can either use an iFrame, or AJAX.
For the iframe, which is the simplest, your form's target would be set to the iframe, thus reloading only that instead of the whole page.

Jquery : Setting selected state on select option items populated via ajax

I have 6 select boxes (sbs), 3 to a row so two rows. The top three sbs contain a list of options that gets populated via php, data is pulled back from mysql. When an option from each box is selected I'm using jquery (via ajax) to pull back option items for the sb immediately below it and populate said sb with corresponding data. I click 'create' and the data is sent via ajax to a php script which then stores the data in a table and returns the submited dropdown data (albeit formatted) in a table below the form. So you might have something that looks like this after creating a 'combination'. Eveyrthying to the left of the colon was an option on the top row of select boxes and then you have selected options from the corresponding box below displayed to the right.
Color: Red | Capacity : 4GB | Model : ABC | EDIT
Color: Blue | Speed: 2GHZ | Capacity : 2GB | EDIT
etc.
If I want to edit the record I click edit and jquery finds the id of the edit button clicked, passes it via ajax to another php script which then returns a json object with the relevant data and this is then used to repopulate the dropdown boxes with the selected options. Everything so far works fine.
My problem is this, only the top row of sbs get one of the options selected when edit is clicked. The child options don't get selected and I can't figure out why. I can get the right options to display but can't set the selected state for whatever matching value is returned in my json object. I've been 8 hours trying to figure it out and tried various things on SOverflow and other sites, none of worked - i'm not that experienced with javascript/ajax to be honest.
Upon a successful ajax process i.e success: I am doing the following:
var jObj = $.parseJSON(html);
//parentVariations# is the select boxes in the top row where
//Color, capacity, model options are displayed.
//The trigger fires off my ajax function which is responsible for
//populating the corresponding child select box with relevant data.
$('#parentVariations1').val(jObj.groupAttr1).trigger('change');
$('#parentVariations2').val(jObj.groupAttr2).trigger('change');
$('#parentVariations3').val(jObj.groupAttr3).trigger('change');
//childVariations# is the child option box, i have the same code for each child
//box but am only showing the first one here for simplicitys sake.
//What I thought I was doing here is getting each option then if the value
//matches that held in my corresponding json object set that option to selected...
//Doesn't work :'(
$("#childVariations1 option").each(function()
{
if($(this).val() == jObj.childAttr1)
{
$("#childVariations1 option").attr('selected','selected');
}
});
Any help would be very welcome as it's driven me over the edge.
$("#childVariations1 option") is an array of all the options. You need to specify which one:
$("#childVariations1 option").eq(1).attr('selected','selected');
If your case, use a for loop and use the index for get the current position, instead of using .each. (or set up a counter)

Delete button in Joomla item view in back-end

I would like to place the delete button from Joomla category view in the item view, so that when a user navigates in backend to that item he would be able to delete it.
I tried to move the function of the delete button from category view to the item view but it doesn't work since that function requires a item to be selected. In item view that particular item should already be selected.
You probably want to use something like this:
if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
JToolBarHelper::deleteList('', 'articles.delete','JTOOLBAR_EMPTY_TRASH');
}
And add a hidden checkbox field in the view with the id variable [i.e. page id] in the view

Categories