Reputation: 65
i try to get selected value from radio button But when i choose teacher it still be s "student"
Html File :
<!DOCTYPE html>
<html ng-app="phase2">
<head>
<title>Sign UP Page</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link href="style.css" rel="stylesheet" />
<script data-semver="1.2.28" src="https://code.angularjs.org/1.2.28/angular.js" data-require="[email protected]"></script>
<script src="https://code.angularjs.org/1.2.28/angular-route.js"></script>
<script src="RigesterationController.js"></script>
</head>
<body >
<center>
<p>Enter Your User Name : <input type="text" , name="UserName" id ="UName" required /> </p>
<p>Enter Your Email : <input type="text" , name="Email" id ="email" required /> </p>
<p>Enter Your Password : <input type="password" , name="pass" id ="Pass" required/> </p>
<p>Choose Gender : <br> Male<input type="radio" name="gender" value="m" id="Gender" checked/> Female<input type="radio" name="gender" value="f" id="Gender"/> </p>
<p>Choose User Type :<br> Student<input type="radio" name="UserType" value="s" id="Utype" checked/> Teacher<input type="radio" name="UserType" value="t" id="Utype"/> </p>
<div ng-app="phase2" >
<div ng-controller="SignUP">
<input type="button" name="signup" value="SignUP" ng-click="save()" />
</div>
</div>
</center>
</body>
</html>
RigesterationController.js File :
var app = angular.module("phase2" , [])
app.controller( "SignUP" ,function ($scope , $http , srvShareData , $location)
{
$scope.dataToShare = [];
$scope.save = function() {
var email= document.getElementById("email").value;
var UName=document.getElementById("UName").value;
var Pass=document.getElementById("Pass").value;
var gender=document.getElementById("Gender").value;
var UserType=document.getElementById("Utype").value;
alert(UserType)
$http.get('http://localhost:8090/SignUp/'+email+'/'+UName+'/'+Pass+'/'+gender+'/'+UserType)
.then(function(response)
{
});
if (UserType=="t")
{
window.location.href="http://localhost:8060/TheAngular_Project/TeacherPage.html";
}
else if (UserType=="s")
{
window.location.href="http://localhost:8060/TheAngular_Project/StudentPage.html";
}
}
});
i get always s although I choose teacher .. how to get selected value ? thanks in advance
Upvotes: 0
Views: 1286
Reputation: 27192
Some suggestions :
Why ng-app="phase2"
two times ?
Why ng-controller
directive only on submit button as form fields(input elements) also the part of the form ?
Why plain Javascript
to get the form data as you can use ng-model
or other angular directives
to communicate between the controller and view ?
DEMO
var myApp = angular.module('phase2',[]);
myApp.controller('SignUP', function($scope) {
$scope.save = function(selectedUser) {
alert(selectedUser);
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="phase2" ng-controller="SignUP">
<form name="myForm" ng-submit="save(uType)">
<p>Choose User Type :<br>Student<input type="radio" name="UserType" value="s" ng-model="uType"/>Teacher<input type="radio" name="UserType" value="t" ng-model="uType"/></p>
<input type="submit" name="signup" value="SignUP"/>
</form>
</div>
Upvotes: 1