Good day. I am still learning Javascript. And I have a function that is called by this button:
<input class='inputButton' type='button' onclick="submit_data('EDIT')">
The function of submit_data looks like this:
function submit_data(mode){
var txtName = $('#txtName').val();
}
Where txtName is the id of a textbox. But suppose I have a variable called $xDate
how do I call it?
var xDate = $('$xDate').val();
like this?
This is the whole submit_data:
function submit_data(mode){
var txtName = $('#txtName').val();
varUrl = "/includes/action.php";
varData = "MODE=" + mode + "&TXT_NAME=" + txtName;
$.ajax({
url: varUrl,
type: 'POST',
data: varData,
success: function(result) {
alert(result);
if(result = 'success'){
redirect_to_parent();
}
else
{
}
}
});
}
And the action.php looks like this:
<?php
include_once("/includes/functions.php");
$_GETVARS = (($_GET <0) ? $_GET : $_POST);
$mode = $_GETVARS['MODE'];
switch ($mode){
case 'EDIT':
break;
default:
print_r($_GETVARS);
break;
}
?>
In short. I need my variable to be accessible in action php. Possibly be included in my $_GETVARS
Sorry for the confusion. $xDate is a variable. I cannot get it from textbox and exist only as a variable.