I have a form and I want from a javascript function to send the form to php with 2 variables that I have in that javascript function
function transfer(old_id){
var select = document.getElementById('trans');
var button = document.getElementById('send_id');
button.addEventListener('click',function(){
var selectedOption = select.value;
alert(selectedOption);
alert(old_id);
document.delete_user.submit();
});
}
I want this line (document.delete_user.submit ();) to send the variables to php: selectedOption and old_id
If you want the form to send the data, then you need to have a form control with the name
you want and the value you want.
If the data exists only in a variable (and isn't already in a form field) then you need to put it in a form field.
Either set the value
property of an existing one (which you can get with, for example, getElementById
) or create a new one (you'd generally want to use a hidden input for this) and append it to the form.