Title explains it all really. I need to take an input from user when they click a particular button and send it to back-end. What I'm looking for is something like:
<button onclick="return confirm('are you sure?')">Click</button>
But instead yes or no I want users to enter a string.
I tried prompt("Please enter your name:", "Harry Potter");
but it doesn't send the input to the back-end. Any idea how can I achieve this?
I want to do it this way because I can't change the front end to add a new input, also this is only needed in a particular button in the form therefore I need it to be added to the request and sent to php.
CodePudding user response:
Sending something to the backend requires an HTTP request either by reloading the page or sending an ajax request.
If you are limited to what you can do on the frontend, you can try something like this:
<button onclick="window.location='http://yoursite.com?name=' prompt('Your name?')">Click</button>
This may or may not work depending on how the frontend is set up
CodePudding user response:
You can try a modal to contain the form, the input and the submit button