Jacob
Jacob

Reputation: 25

Set a $_POST variable

How can I set a $_POST variable using jQuery or JavaScript, and without using an Ajax library?

Upvotes: 2

Views: 4119

Answers (2)

L0j1k
L0j1k

Reputation: 12635

You can do this with javascript very simply by adding an onclick="click();" property to the button or link you are trying to get, then writing a small function click() { to handle the var value = document.GetElementById('textBoxId').value.

EDIT: This is to "get" a variable, not "set" a variable, but you can still use these ideas to perform an action based on the user clicking the button and then retrieving the value of the field.

Upvotes: 0

Ohgodwhy
Ohgodwhy

Reputation: 50787

jQuery is the library, ajax is not. Ajax is an implementation of the XHR Object written as a jQuery method.

$.ajax({
    type: 'POST',
    url: 'path/to/my/controller.ext',
    data: 'myvar=something'
});

PHP.

if(isset($_POST['myvar'])):
    //you now have reference to myvar, which has a value of something.
endif;

Upvotes: 2

Related Questions