Skip to content
Advertisement

How to send a form with 2 values ​from javascript?

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

JavaScript

I want this line (document.delete_user.submit ();) to send the variables to php: selectedOption and old_id

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement