简体   繁体   中英

how to send a hole form's attributes with onsubmit()?

<form method='post' name='...' action='index.html' onsubmit='function(x,z,u)'>

I want to send every element of my form that will be sent a PHP file with

xmlhttp.open("GET","user.php?q="+str,true) 

What are the proper sintaxes of submitting more than one variables with Onsubmit() and the xmlhttp.open() ?

I'm self taught, I can double thank you if I can use the code later in the program.

You want something like this:

xmlhttp.open("GET", "user.php?q1="+encodeURIComponent(x)+"&q2="+encodeURIComponent(y)+"&q3="+encodeURIComponent(z), true);

It would be easier if you used a library like jQuery. If you want all the inputs from a form, you can use its $.serialize() function. If you need to calculate the values to send, it has $.get and $.post functions that allow you to supply the parameters as an object and it will take care of all the encoding.

Do you really need AJAX? If you want to send form element to php file, why can't you set it in action attribute?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM