user1166981
user1166981

Reputation: 1746

How to set a variable from form submit for use in AJAX call?

I have the below form:

  <form action="test.php" method="POST" onsubmit="loadXMLDoc(this.form); return false;">
  <input class="com" type="text" name="test" />
  </form>

Instead of "this.form", what would need to be in its place so that the text input by the user is passed to loadXMLDoc?

Also: is that the correct syntax to then send this variable data?

function loadXMLDoc($testVariable)

//standard ajax code..

xmlhttp.send("test=" + $testVariable);

Upvotes: 0

Views: 50

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191829

The form can reference input elements by name as properties.

loadXMLDoc(this.test.value);

Upvotes: 1

Related Questions