When working with AngularJS, I can access form variables within my function like this (for example: s1 = Joe Smith).
However, I have a need to update the Indata variable by replacing the a_searchvalue1 with the value stored in s1 but wrapped in quotes.
Original:
var Indata = { what_to_do: "angular_users5", where_clause: '[{"sqlvalue1":"a_earchvalue1","sqlvalue2":"b_earchvalue2"}]' }
resulting in:
var Indata = { what_to_do: "angular_users5", where_clause: '[{"sqlvalue1":"Joe Smith","sqlvalue2":"b_earchvalue2"}]' }
<div id="myapp" ng-controller="empcontroller">
<input id="name1" type="text" placeholder="Name" required name="Name" value="Joe Smith">
<input id="email1" type="text" placeholder="Email" required name="Email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a4d5f58595b494e4a555b7a5d575b535614595557">[email protected]</a>">
<p id="sample">demo1</p>
<button ng-click="postData()">Submit</button><br>
</div>
<script>
var app = angular.module('demoApp', []);
app.controller('empcontroller', function($scope, $http)
{
$scope.postData = function ()
{
var s1 = document.getElementById("name1").value;
alert(s1);
var Indata = { what_to_do: "angular_users5", where_clause: '[{"sqlvalue1":"a_earchvalue1","sqlvalue2":"b_earchvalue2"}]' }
var req =
{
method: 'POST', url: 'angular_master.php',
headers: {'Content-Type': undefined },
params: Indata
}
$http(req).then(function (response)
{
$scope.names = response.data.records;
document.getElementById("sample").innerHTML = "YOU CLICKED THE BUTTON";
alert(angular.toJson(response.data.records));
});
}
});
</script>
Additionally, I'm looking for a way to handle input fields that contain double quotes.