XMLHttpRequest not working on button click null - html

I have a page and when I click on this page with "trigger" I can print the "#content" page. but I want it to return to the "home" I want with the "BACK" button on the page that comes up, but it just doesn't work. Where am I making the mistake?
index.php
<div class="app-content content" id="content">
<?php require 'home' ?></div>
home.php
<div id="kasaButton">
<a type="button" href="#" data-target="contact"> Contact</a>
<a type="button" href="#" data-target="gallery"> Gallery</a>
</div>
<div class="card">
<table class="datatables-basic table">
<thead>
<tr>
<th>İD</th>
<th>NAME</th>
</tr>
</thead>
<tbody>
<tr>
<td>İD</td>
<td>NAME</td>
</tr>
</tbody>
</table>
</div>
gallery
<div class="card-body">
<form action="" method="post">
<input type="text" class="form-control" placeholder="Cari Adı" value=""/>
<button id="save" type="submit">SAVE</button>
<button id="back" type="button">BACK</button>
</form>
</div>
$(document).ready(function () {
var trigger = $("#kasaButton a"),
container = $("#content");
trigger.on("click", function () {
var $this = $(this)
target = $this.data('target');
container.load(target);
return false;
});
});
$(document).ready(function () {
$("#back").on("click", function () {
$("#content").load('home');
});
})

Just add a div with the id of "content"
here is an example of gallery.php:
<div class="card-body">
<form action="" method="post">
<input type="text" class="form-control" placeholder="Cari Adı" value=""/>
<button id="save" type="submit">SAVE</button>
<button id="back" type="button">BACK</button>
</form>
</div>
<div id="content"></div>
<script>
$(document).ready(function () {
var trigger = $("#kasaButton a"),
container = $("#content");
trigger.on("click", function () {
var $this = $(this)
target = $this.data('target');
container.load(target);
return false;
});
});
$(document).ready(function () {
$("#back").on("click", function () {
$("#content").load('home.php');
});
})
</script>

Related

Create a show all button to show hidden row

My code is like this: when you check the 'hide' column, the whole row is hidden. I also have a 'Show All' checkbox. When I check it, all rows (including the hidden ones) are shown. But when I uncheck it, all rows disappear. How can I make it so only the hidden rows disappear when I uncheck 'Show All', and the other rows still remain visible?
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall" ng-hide="hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>
<script>
var app = angular.module("myApp", []);
app.controller('myController', function ($scope, $window) {
$scope.fruitnameDetail = [
{
"fruitname": "Banana"
},
{
"fruitname": "Mango"
},
{
"fruitname": "Orange"
}
];
$scope.addnew = function () {
var fruitnameDetail = {
fruitname: $scope.mdfruitname
};
$scope.fruitnameDetail.push(fruitnameDetail);
$scope.mdfruitname = '';
};
$scope.removefruitname = function (index) {
var name = $scope.fruitnameDetail[index].fruitname;
if ($window.confirm("Do you want to delete " + name + " ?")) {
$scope.fruitnameDetail.splice(index, 1);
}
};
});
</script>
Do not use ng-show and ng-hide at the same time. Just change a little bit your condition for ng-repeat. Here the example that should work:
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall || !hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>

Directive for confirm dialog when click submit button

I have a form to create an employee.
When I click the submit button I need to confirm with the confirm dialog box as 'do you want to submit' form?
In angularjs and bootstrap design, if it's possible.
<form ng-submit="create()">
<input type="text" ng-model="fstname">
<input type="text" ng-model="lstname">
<input type="submit" value="submit">
</form>
When I click the submit button, if the form is valid then I want to confirm with confirm box. If I click ok, that means I want to submit the form else it should not submit.
finally i found my answer for this question.my view page code look like below
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="ModalDemoCtrl" class="modal-demo">
<br>
<form name="form" novalidate>
<input type="text" style="width:200px" class="form-control" name="name" ng-model="text.name" required>
<span ng-show="form.$submitted && form.name.$error.required">name is required</span><br>
<input type="text" style="width:200px" class="form-control" name="name1" ng-model="text.name1" required>
<span ng-show="form.$submitted && form.name1.$error.required">name1 is required</span><br>
<input type="submit" ng-click="open(form)">
</form><br>
<p ng-hide="!msg" class="alert" ng-class="{'alert-success':suc, 'alert-danger':!suc}">{{msg}}</p>
</div>
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">Your Details</h3>
</div>
<div class="modal-body" id="modal-body">
<p>Are you sure, your name <b>{{name }}</b> is going to submit?
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">Submit</button>
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
</div>
</script>
<script>
and my controller code looks below
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope,$uibModal, $log, $document) {
var $ctrl = this;
$scope.animationsEnabled = true;
$scope.text = {};
$scope.open = function (form) {
if(form.$valid)
{
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
values: function () {
return $scope.text;
}
}
});
modalInstance.result.then(function () {
console.log($scope.text);
$scope.msg = "Submitted";
$scope.suc = true;
}, function(error) {
$scope.msg = 'Cancelled';
$scope.suc = false;
});
}else{
alert('');
}
};
});
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope,$uibModalInstance, values) {
var $ctrl = this;
$scope.name= values;
$scope.ok = function () {
$uibModalInstance.close('ok');
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});
my updated plunkr here demo

How to pass value to bootstrap modal?

I'm using Bootstrap to display my modal in my webpage. My data is stored in database. I used ng-repeat to get my array data from database. I want to pass my room.room_name into modal. How can I do that?
HTML:
<tr data-ng-repeat="room in data">
<td>{{room.room_id}}</td>
<td>{{room.room_name}}</td>
<td>{{room.max_pax}}</td>
<td>{{room.no_booked}}</td>
<td>
<button class="btn btn-warning" data-toggle="modal" data-target="#editRoom"></button>
<button class="btn btn-danger" data-ng-click="delRoom(room.room_id)"></button>
</td>
</tr>
My Modal:
I want to pass room_room.name value and insert into input text value.
I tried to use ng-value but failed.
<div id="editRoom" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Library Discussion Room</h4>
</div>
<div class="modal-body">
<form>
<label for="editName">Room Name: </label>
<input type="text" name="editName" data-ng-model="room.name" id="editName" data-ng-value="{{room.room_name}}" />
<br />
<label for="editMaxPax">Maximum Person: </label>
<input type="text" name="editMaxPax" data-ng-model="room.maxPax" id="editMaxPax" value="room.max_pax" />
<button type="submit" class="btn btn-default" data-ng-click="editRoom(room)">Edit</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
AngularJS (Controller):
My get the value from database and store it into array named "data".
var app = angular.module("myApp", ['ngRoute']);
app.config(['$routeProvider', function ($routeProvider) {
"use strict";
$routeProvider
.when("/", {
templateUrl: "facilities.html"
});
}]);
app.controller("myCtrl", function ($scope, $http) {
"use strict";
$scope.state = "";
$scope.addRoom = function (room) {
$http.post("add_library_room.php", {'room_name': room.name, 'max_pax': room.maxPax})
.then(function () {
$scope.msg = "Room is inserted into database.";
});
};
$scope.displayRoom = function () {
$http.get("view_library_room.php")
.then(function (response) {
var data = response.data;
$scope.data = data;
console.log(data);
});
};
$scope.delRoom = function (roomID) {
$http.post("del_library_room.php", {'room_id': roomID})
.then(function () {
$scope.msg = "Room is deleted successfully.";
});
};
$scope.footer = function (page) {
if (page === "login") {
$scope.state = page;
} else {
$scope.state = "";
}
return $scope.state;
};
});

How to show and hide <div>'s in Popover using AngularJS

I am working on SPA (Single Page Application) for Online Team Collaboration service(OTC) ,and I include HTML pages by ng-include,in some included page there is a popover ,this one contains a possibility for creating a public group chat,and in order to create one ,the user must submit, now my question is : how can i display a "successfully created" message in the same popover instead of the main div for creating the group in the popover?
The external page (the page that include other pages):
<div ng-show="ctrChanneldiv" ng-contoller="ctrChannelCon" style="float: right;" class="col-md-3">
<div ng-include="'CreateChannel.html'" ></div>
</div>
The Controller ctrChannelCon:
appvar.controller('ctrChannelCon',['$scope','$http','$rootScope',function($scope, $http, $rootScope){
$scope.createBtn = function() {
$http.post("http://localhost:8080/ExampleServletv3/crtchannelservlet",this.crtchannel)
.success(function(response) {
setTimeout(function () {
$scope.$apply(function(){
//******* Here Display "Successfully Created" In the Popover *******//
});
});
});
};
}]);
In CreateChannel.html :
<div>
<div class="row">
<a href="#" class="popper" data-toggle="popover"
data-placement="bottom"><span class="glyphicon glyphicon-plus"></span>Create Channel</a>
<div class="popper-content hide">
<div class="form-group">
<!-- ng-controller="createChannelCon" -->
<div class="form-group">
<label>Channel name:</label>
</div>
<div class="form-group">
<input ng-model="crtchannel.Name" type="text" placeholder="enter channel's name" maxlength="30"
class="form-control input-md" required />
</div>
<div class="form-group">
<label>Description:</label>
</div>
<div class="form-group">
<textarea cols="15" ng-model="crtchannel.Description" type="text"
placeholder="enter channel's description" maxlength="500"
class="form-control input-md" required></textarea>
</div>
<div>
<input ng-model="crtchannel.Type" type="radio" name="chtype"
value="private" required /> Private<br> <input
ng-model="crtchannel.Type" type="radio" name="chtype"
value="public" /> Public<br>
</div>
<div class="form-group">
<button ng-click="createBtn()" class="btn btn primary">Apply</button>
</div>
</div>
</div>
<script>
$('.popper').popover({
container : 'body',
html : true,
content : function() {
return $(this).next('.popper-content').html();
}
});
</script>
</div>
</div>
Any suggestions?
Thanks
You may use ngClass directive to counter this problem. ngClass directive allows conditional application of classes. Create a div for successfully created in the popup and set up ng-class directive with a variable in the scope and assign it true and false as per your requirement.
JS
appvar.controller('ctrChannelCon',['$scope','$http','$rootScope',function($scope, $http, $rootScope){
$scope.createBtn = function() {
$http.post("http://localhost:8080/ExampleServletv3/crtchannelservlet",this.crtchannel)
.success(function(response) {
setTimeout(function () {
$scope.$apply(function(){
//******* Change value of a model *******//
$scope.hidden = false;
});
});
});
};
}]);
HTML
<span ng-class="{hide: hidden}">Successfully Created</span>
CSS
.hide { display: none; }
Set a flag in your controller on success and use this flag to show or hide the success message:
...
<div class="form-group">
<button ng-click="createBtn()" class="btn btn primary">Apply</button>
</div>
<div ng-show="isSuccess">Successfully Created</div>
Inside the controller:
$scope.isSuccess = false;
$scope.createBtn = function() {
$http.post("http://localhost:8080/ExampleServletv3/crtchannelservlet",this.crtchannel)
.success(function(response) {
setTimeout(function () {
$scope.$apply(function(){
//******* Here Display "Successfully Created" In the Popover *******//
$scope.isSuccess = true;
});
});
});
};

ReactJS <p/> or <br/> not working in render()

I can't get <p/> or <br/> to create new lines when used after a custom ReactJS component that uses this Bootstrap CSS in the form <div className="col-sm-10"> i.e.
var MyChatClientView = React.createClass({
render: function() {
return (
<div>
<h2>Chat</h2>
<span>Type something</span>
<MyChatForm />
<p/>
<br/>
<div>
This text is on the same line as MyChatForm, I want it on a new line!
</div>
</div>
);
}
});
var MyChatForm = React.createClass({
handleSubmit: function(e) {
e.preventDefault();
var myChatTxt = this.refs.myChatTxt.getDOMNode().value.trim();
},
render: function() {
return (
<div>
<form role="form" onSubmit={this.handleSubmit}>
<div className="form-group">
<input type="textarea" className="form-control" id="post-chat" ref="myChatTxt" />
</div>
<div className="form-group">
<div className="col-sm-10">
<button type="submit" className="btn btn-primary btn-lg btn-block">Send</button>
</div>
</div>
</form>
</div>
);
}
});
To size form controls using Bootstrap, either (1) your form needs the form-horizontal class or (2) your columns need to be wrapped in an element with the row class.
This is covered in the control sizing section of the Bootstrap docs.
In your case it seems to make sense to replace the form-group with the needed row:
var MyChatForm = React.createClass({
handleSubmit: function(e) {
e.preventDefault();
var myChatTxt = this.refs.myChatTxt.getDOMNode().value.trim();
},
render: function() {
return (
<div>
<form role="form" onSubmit={this.handleSubmit}>
<div className="form-group">
<input type="textarea" className="form-control" id="post-chat" ref="myChatTxt" />
</div>
<div className="row">
<div className="col-sm-10">
<button type="submit" className="btn btn-primary btn-lg btn-block">Send</button>
</div>
</div>
</form>
</div>
);
}
});