0

Is there a way in AJAX or JS to add further inputs upon a button click?

3 Answers 3

2

In short, yes you can add more inputs on a button click.

For example, in jQuery, you could have something like this where the buttonID is the id attribute for the button and the formID is the id attribute for your form:

$("buttonID").click(function() {
    //add new inputs here, something like:
    $("formID").append('<input type="text" id="newInput" name="newInput" />');
});

You can also have the additional inputs hidden to start off with and then 'un-hide' them on a click if you want.

Sign up to request clarification or add additional context in comments.

Comments

1

Further inputs? Run any JavaScript you want when a user clicks a button by adding an event listener to the button that listens for a click.

Comments

0

Once a user clicks on the button, if you have an event listener, you can change what they had entered, you can do anything anything you want.

I am not certain what you mean by 'further inputs' though. If you are sending data then you can append whatever you want, I frequently append a timestamp to help prevent caching issues, for example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.