Reputation: 25
How can I set a $_POST
variable using jQuery or JavaScript, and without using an Ajax library?
Upvotes: 2
Views: 4119
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
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