WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom form field within a taxonomy. However when a new term/tag has been added I need to clear some values through javascript. How can I do this?

I found the following code snippet in WordPress:


    var f=wpAjax.parseAjaxResponse(h,"ajax-response");


var g=b.find("select#parent").val();

    a(".tags #tag-"+g).after(f.responses[0].supplemental.noparents)}

a(".tags .no-items").remove();


var e=f.responses[1].supplemental;
var c="";

for(var d=0;d<f.responses[1].position;d++){c+="&nbsp;&nbsp;&nbsp;"}

b.find("select#parent option:selected").after('<option value="'+e.term_id+'">'+c+e.name+"</option>")}

// = NOTE THE FOLLOWING LINE =============
a('input[type="text"]:visible, textarea:visible',b).val("")});
// =======================================

return false})});

It clears all the text input fields that are visible, however I have my own custom field that people can select an image and after the image has been selected a hidden input field value is changed with the selected image id and the image is shown through an image object.

However, after the user presses the 'Add new category' button I like to be able to reset the hidden input field and remove the image object.

I like to know when a category has been added so I can reset all that is necessary.

share|improve this question

Could you be more specific on the "when a new term/tag has been added" part? Are you doing it yourself, as in you call the backend through admin-ajax.php and update the front-end accordingly? Including some code or a link to jsFiddle wouldn't hurt.

There's a create_term action you can hook into in the back-end. Just put this into functions.php or your plugin code:

function your_create_fn( $term_id, $tt_id, $taxonomy ){
    // do your thing here
add_action( 'create_term', 'your_create_fn', 10, 3 );

Alternatively, if you're doing it yourself then you obviously control the entire process, so you know exactly when you've successfully added a new term and can return something to the JS function that indicates you need to clear those values.

share|improve this answer
I edited my question. – Mark Mar 11 '13 at 17:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.