I have Webpage written using PHP that displays drop down data from MySQL tables. I want my page to refresh and appeared new entry list in drop down list, after new records are entered to the database.I want auto refresh but when submit the form only.

Dani AI

Generated

Brief summary tied to the posts: is opening an add/edit Category form in a GrayBox and wants the parent page select to show the new item without a full page reload. As suggested, the exact technique depends on how you insert the record (normal submit, AJAX, iframe). Two reliable patterns follow.

Parent-side: fetch-and-rebuild (recommended)
This keeps logic in one place and works whether the popup used AJAX or a normal submit. The parent page provides a refresh function that requests a small JSON list and rebuilds the <select>.

function refreshCategories(selectedId) {
  $.getJSON('/ajax/get_categories.php', function(list) {
    var $sel = $('#categorySelect').empty();
    $.each(list, function(i, c){
      $sel.append($('<option>').val(c.id).text(c.name));
    });
    if (selectedId) $sel.val(selectedId);
  }).fail(function(){ console.log('Failed to reload categories'); });
}

Popup-side: notify the parent after successful insert
If the GrayBox content runs in an iframe (the common case), call the parent function after the insert completes:

// inside the popup, after successful insert (server returns newId/newName)
if (window.parent && typeof window.parent.refreshCategories === 'function') {
  window.parent.refreshCategories(newId); // optional: pass new id to select it
}

Append-single-option alternative (faster)
If the server returns just the new row, append it directly to avoid fetching the whole list:

// parent jQuery call from popup
var $sel = parent.$('#categorySelect');
if ($sel.find('option[value="'+id+'"]').length === 0) {
  $sel.append($('<option>', {value: id, text: name}).prop('selected', true));
} else {
  $sel.val(id);
}

Troubleshooting & cautions

  • Same-origin: parent/iframe must be same origin to call parent functions.
  • If GrayBox exposes a close callback, trigger refresh on that event.
  • Protect AJAX endpoints with CSRF tokens and escape output.
  • If you cannot reach the parent due to plugin limits, fallback to closing the popup and reloading the page (location.reload()).

The minimal change is to implement one parent refresh function and call it from the popup after successful insert. That covers add/edit workflows without a full page reload.

Recommended Answers

All 2 Replies

I have Webpage written using PHP that displays drop down data from MySQL tables. I want my page to refresh and appeared new entry list in drop down list, after new records are entered to the database.I want auto refresh but when submit the form only.

Hi, Im not very expert in php, but the autorefresh depends how do you insert the new record into DB ? explain how you will insert new records into DB and I will try to help you in this.

Regards

I have Webpage written using PHP that displays drop down data from MySQL tables. I want my page to refresh and appeared new entry list in drop down list, after new records are entered to the database.I want auto refresh but when submit the form only.

I am use gray box popup.I view default category in drop down list with mysql fetch query which list fetch database,if user visit in the our profile add/edit new Category,after add/edit new category after submit page and when close graybox then automatic view new category list in drop down without page refresh.
Please Reply Advance.
Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.