Display the Output in the same textbox in visual studio - html

When i am giving the details, it will print in the new text box whatever values i am assigning, but i want to print the same values which i am giving in the textbox itself. I am using [httppost] and [httpGet] commands for this.
in View page i have this code :
#{
ViewBag.Title = "LoginPage";
}
<h1>LoginPage</h1>
<form method="post" action="/Home/LoginPage" >
<table>
<tr>
<td>First Name : </td>
<td><input type="text" id="txt.Fname" name="F_FIRSTNAME" class="form-control"/> </td>
</tr>
<tr>
<td> Last Name : </td>
<td><input type="text" id="txt_LNAME" name="L_LastName" class="form-control"/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" id="txt_Password" name="P_PASSWORD" class="form-control" /> </td>
</tr>
<tr>
<td>Email ID : </td>
<td><input type="email" id="txt_emailid" name="E_EmailID" class="form-control" /> </td>
</tr>
<tr>
<td><input type="submit" id="txt_Enter" name="Enter" class="btn-primary" /></td>
</tr>
</table>
</form>
#{
if(IsPost==true)
{
string name1 = Request["F_FIRSTNAME"];
if(!string.IsNullOrEmpty(name1))
{
<h2 style=" color:aquamarine;" > <input type="text" value="#name1" /> </h2>
}
string name2 = Request["L_LASTNAME"];
if (!string.IsNullOrEmpty(name2))
{
<h2 style="color:blue;"> <input type="text" value="#name2" /> </h2>
}
string name3 = Request["P_PASSWORD"];
if (!string.IsNullOrEmpty(name3))
{
<h2 style="color:blue;"> <input type="text" value="#name3" /> </h2>
}
string name4 = Request["E_EMAILID"];
if (!string.IsNullOrEmpty(name4))
{
<h2 style="color:blue;"> <input type="text" value="#name4" /></h2>
}
else
{
<h5>This is a get request </h5>
}
}
}
and in controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication3.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult LoginPage()
{
return View();
}
[HttpPost]
public ActionResult AfterLoginPage(string F_FIRSTNAME, stringL_LASTNAME, string P_PASSWORD, string E_EMAILID)
{
return View("LoginPage");
}
}
}
[As you can see the credentials are displaying in separate text box which i created but i want to display it on the same text box ][enter image description here]1

Simply you can change your form and replace the code below:
<form method="post" action="/Home/LoginPage">
<table>
<tr>
<td>First Name : </td>
<td><input type="text" id="txt.Fname" name="F_FIRSTNAME" class="form-control" value="#(IsPost ? Request["F_FIRSTNAME"]:"")" /> </td>
</tr>
<tr>
<td> Last Name : </td>
<td><input type="text" id="txt_LNAME" name="L_LastName" class="form-control" value="#(IsPost ? Request["L_LastName"]:"")" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" id="txt_Password" name="P_PASSWORD" class="form-control" value="#(IsPost ? Request["P_PASSWORD"]:"")"/> </td>
</tr>
<tr>
<td>Email ID : </td>
<td><input type="email" id="txt_emailid" name="E_EmailID" class="form-control" value="#(IsPost ? Request["E_EmailID"]:"")"/> </td>
</tr>
<tr>
<td><input type="submit" id="txt_Enter" name="Enter" class="btn-primary" /></td>
</tr>
</table>
</form>
And you can remove the rest of View code. I haven't tested it but I guess it works, although it's not the proper solution. It's better to have a separate Model or ViewModel for that.

Related

Need Ignor required field in some case

Greeting,
I need to avoid validation for required field. When I click one button and this field will be required, and form will not submitted unless... And if I click another button, required field will be ignored, and the form submitted(Both are buttons within the same form for example).
<cfform name="SubmitToHR" action="Action.cfm">
<table>
<tr>
<td class="Form" bgcolor="FFFBF0">#Var#</td>
<td width="39">
<cfinput type="Text" value="#Comments#" name="Comment" size="39" maxlength="100" lass="Text5" style="height:21" required="no">
</td>
<td width="127">
<cfinput name="CheckDate" type="datefield" value="#Paycheck#" class="Text" style="height:21" size="18" required="yes" message="Select Date">
</td>
</tr>
</table>
<table>
<tr>
<td class="Center">
<cfinput name="Operation" type="submit" class="ButtonOrange" value="Submit">
</td>
</tr>
<tr>
<td class="Center">
<cfinput name="Operation" type="submit" class="ButtonRed" value="Not Approve">
</td>
</tr>
Something like this?
<script>
function checkInput(mode)
{
if (mode == 1) {
if (SubmitToHR.CheckDate.value.length == 0)
{
window.alert('Select Date');
} else {
document.forms['SubmitToHR'].submit();
}
} else if (mode == 2) {
document.forms['SubmitToHR'].submit();
}
return false;
}
</script>
<cfset Var = "Test1">
<cfset Comments = "Test1">
<cfset Paycheck = "01/01/2020">
<form name="SubmitToHR" method="post" action="Action.cfm">
<cfoutput>
<table>
<tr>
<td class="Form" bgcolor="FFFBF0">#Var#</td>
<td width="39">
<input type="Text" value="#Comments#" name="Comment" size="39" maxlength="100" class="Text5" style="height:21" required="no">
</td>
<td width="127">
<input name="CheckDate" type="Text" value="#Paycheck#" class="Text" style="height:21" size="18" required="no" message="Select Date">
</td>
</tr>
</table>
<table>
<tr>
<td class="Center">
<input name="Operation" type="button" class="ButtonOrange" value="Submit" onclick="checkInput(1);">
</td>
</tr>
<tr>
<td class="Center">
<input name="Operation" type="button" class="ButtonRed" value="Not Approve" onclick="checkInput(2);">
</td>
</tr>
</table>
</cfoutput>
</form>

How do i submit my angular form?

I have my edit page and i would like to submit info to db once fields have been edited, it seems like something simple yet i cannot find a good example that pertains to my situation, i really don't know how to go about resolving this, this is the last part of my project. I would appreciate any suggestions Please.
This is my edit page code:
<title>
</title>
</head>
<body ng-app="app" ng-controller="decontroller" class="container">
<div id="banner" style="text-align:center; margin-left:auto; margin- right:auto; display:block;">
</div>
<h2></h2>
<h3>Personal Information:</h3>
<div id="validation-errors">
</div>
<form action="" method="post" accept-charset="utf-8" ng-submit="addEdit()">
<table class="table table-bordered">
<tbody>
<tr>
<td>ParticipantID</td>
<td>{{edit.Stlc_id}}</td>
</tr>
<tr>
<td>First Name:<br>
</td>
<td>{{edit.First_Name}}</td>
</tr>
<tr>
<td>Last Name:<br>
</td>
<td>{{edit.Last_Name}}</td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name ="Address" ng-model="edit.Address" ></td>
</tr>
<tr>
<td>Phone:</td>
<td><input size="20" name ="phone" ng-model="edit.Phone_Number" ></td>
</tr>
<tr>
<td>Assistive Devices:</td>
<td><input name ="AssistiveDevices" ng-model="edit.Assistive_Devices" ></td>
</tr>
<tr>
<td>Lanyard Code</td>
<td>
<input name ="Lanyard_Status" ng-model="edit.Lanyard_Status" /> </td>
</tr>
<tr>
<td>Comments</td>
<td>
<textarea cols="100" name="comments" ng-model="edit.Comments">.</textarea>
</td>
</tr>
<tr>
<td>Disenrolled</td>
<td><input name="disenrolled" ng-model="edit.Disenrolled" ></td>
</tr>
<tr>
<td>Deceased</td>
<td><input name="deceased" ng-model="edit.Deceased" ></td>
</tr>
</tbody>
</table>
</form>
<h3>Days in Center<br></h3>
<table class="table table-bordered">
<tbody>
<tr>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
<tr>
<td><input name="Attendance_Monday" ng-model="edit.Attendance_Monday" ></td>
<td><input name="Attendance_Tuesday" ng-model="edit.Attendance_Tuesday" ></td>
<td><input name="Attendance_Wednesday" ng-model="edit.Attendance_Wednesday" ></td>
<td><input name="Attendance_Thursday" ng-model="edit.Attendance_Thursday" ></td>
<td><input name="Attendance_Friday" ng-model="edit.Attendance_Friday" > </td>
</tr>
</tbody>
</table>
<h3>Transportation Types</h3>
<table class="table table-bordered">
<tr>
<td>Type of Transportation</td>
<td>Approved For</td>
<td>Comments</td>
</tr>
<tr>
<td width="300px">Wheel Chair Van</td>
<td><input name="WheelChair_Van" ng-model="edit.WheelChair_Van"></td>
<td><textarea cols="100" name="WheelChair_Van comments" ng-model="edit.Comments" ></textarea></td>
</tr>
<tr>
<td width="300px">Transit Van 240</td>
<td><input name="TransitVan_240" ng-model="edit.TransitVan_240"></td>
<td><textarea cols="100" name="TransitVan_240 comments" ng-model="edit.Comments" ></textarea></td>
</tr>
<tr>
<td width="300px">Transit Van 360</td>
<td><input name="TransitVan_360" ng-model="edit.TransitVan_360"></td>
<td><textarea cols="100" name="TransitVan_360 comments" ng- model="edit.Comments"></textarea></td>
</tr>
<tr>
<td width="300px">Subaru Impreza</td>
<td><input name="Subaru_Impreza" ng-model="edit.Subaru_Impreza"></td>
<td><textarea cols="100" name="Subaru_Impreza comments" ng- model="edit.Comments"></textarea></td>
</tr>
</table>
<h3>Pick up and Drop Off Times</h3>
<br>
<table class="table table-bordered">
<tr>
<td width="300px">Pick Up Time:</td><td><input type="text" name="Pick_Up_Time" value=""></td>
</tr>
<tr>
<td width="300px">Drop off Time</td><td><input type="text" name="Drop_Off_Time" value=""></td>
</tr>
</table>
<br>
<h3>Personal Care Hours Pick Up/Drop Off</h3>
<table class="table table-bordered">
<tbody>
<tr>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
<td>Saturday</td>
<td>Sunday</td>
</tr>
<tr>
<td><input type="text" name="Monday_Pick_Up" ng-model="edit.Monday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Tuesday_Pick_Up" ng-model="edit.Tuesday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Wednesday_Pick_Up" ng-model="edit.Wednesday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Thursday_Pick_Up" ng-model="edit.Thursday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Friday_Pick_Up" ng-model="edit.Friday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Saturday_Pick_Up" ng-model="edit.Saturday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Sunday_Pick_Up" ng-model="edit.Sunday_Pick_Up" placeholder="Pick Up Time"></td>
</tr>
<tr>
<td><input type="text" name="Monday_Drop_Off" ng-model="edit.Monday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Tuesday_Drop_Off" ng-model="edit.Tuesday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Wednesday_Drop_Off" ng-model="edit.Wednesday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Thursday_Drop_Off" ng-model="edit.Thursday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Friday_Drop_Off" ng-model="edit.Friday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Saturday_Drop_Off" ng-model="edit.Saturday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Sunday_Drop_Off" ng-model="edit.Sunday_Drop_Off" placeholder="Drop Off Time"></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" ng-click="saveEdit()" />
</form>
<pre>{{edit | json}}</pre>
<a href="http://localhost:8080/stlc/index.php/transport/list_show_data/transport_vi ew">
<button type="button" class="btn btn-primary">Back</button>
</a>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"> </script>
<script type="text/javascript">
var app = angular.module('app',[]);
app.controller('decontroller', function($scope,$http){
$scope.edit=<?php echo json_encode($aggregate_data_view);?>;
$scope.saveEdit = function(){
console.log("hey i'm submitting!");
console.log($scope.edit);
$http.post('?php echo site_url("index.php/transport/saveData")?>', $scope.edit).
success(function(data){console.log(":)") }).
error(function(data){
console.log(":(")
});
};
});
</script>
</body>
</html>
Here is my Controller:
public function saveData()
{
}
it is empty now cause i really don't know what to do,nothing has worked.
In my page I have three button. First two create random AVL data on the page
the second one save that data to the db
HTML:
<button data-ng-click="createAvl()">Create Avl</button>
<button data-ng-click="create1000Avl()">Create 1000 Avl</button>
<button data-ng-click="saveAvl()">Save Avl</button>
ngController:
app.controller("myCtrl", function ($scope, $http) {
$scope.avl = []; --here is where i save the avl
$scope.avl.push({
'tracker_avl_id': getRandomArbitrary(0, 1000000, 1),
'plate_num': getRandomArbitrary(0, 10000, 1),
'x_lat': getRandomArbitrary(-69, -66, 0),
'y_long': getRandomArbitrary(8, 10, 0),
'azimuth': getRandomArbitrary(0, 359, 1),
'engine_status': engine,
'gps_fix': gps_fix,
'event_time': getRandomDate()
});
$scope.saveAvl = function () {
$scope.ResponseDetails = 'Working...'; -- some variables to show progress
$scope.startDate = getDate();
$scope.startTime = new Date().getTime();
$scope.timeEllapsed = null;
-- use $.param jQuery function to serialize data from JSON
var data = $.param({
avl_list: $scope.avl
});
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
-- send the data to my webservice
$http.post('/AvlApi/putTrackerAVL', data, config)
.success(function (data, status, headers, config) {
var end = new Date().getTime() - $scope.startTime;
$scope.timeEllapsed = 'milliseconds passed: ' + end;
$scope.ResponseDetails = data;
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
};
My Webservice is in IIS using C#
[HttpPost]
public JsonResult putTrackerAVL(List<avl> avl_list)
{
try
{
avl_list.ForEach(car => db.avl.Add(car));
db.SaveChanges();
}
catch (Exception ex)
{
return Json(new { status = "Fail", message = ex.InnerException });
}
return Json(new { status = "Success" });
}

How to add multiple column in a table on a button action

I have a table were I want to add multiple columns with values when I click an add button. I have a drop down of Rulelist after selecting rule I have a button that rule pass to the controller search the object of that particular rule and display in a table. Now I am facing a problem after adding one column when I want to add another the first column gets removed.
Html
<form:form action="/update" method="post" id="ruleListForm" modelAttribute="ruleListContainer">
<table border="1">
<thead>
<h3 align="center">Selected Rule</h3>
<tr>
<th data-field="id" width="25"> ID </th>
<th data-field="details" width="20">RuleName</th>
<th data-field="details" width="10">StartDate</th>
<th data-field="details" width="10">EndDate</th>
<th data-field="parameter" width="240">Parameter </th>
</tr>
</thead>
<tbody id="ruleListContainer">
<c:forEach items="${ruleList}" var="as" varStatus="vs">
<tr class="rule">
<td><input type="hidden" name="ruleList[${vs.index}].id" value="${as.rule.id}" /> ${as.rule.id}</td>
<td><input type="hidden" name="ruleList[${vs.index}].ruleName" value="${as.rule.ruleName}" /> ${as.rule.ruleName}</td>
<td> <input id="one" class="datepicker" type="text" name="ruleList[${vs.index}].startDate" size="11" height="0.10"></td>
<td> <input id="two" class="datepicker" type="text" name="ruleList[${vs.index}].endDate" size="11" height="0.10"></td>
<td>
<table border="1">
<c:forEach items="${as.ruleParameter}" var="asss">
<tr>
<td><input type="hidden" name="ruleList[${vs.index}].ruleParameter[${assignments.index}].parameterName"value="${asss.parameterName}"> ${asss.parameterName}</td>
<td><input type="hidden" name="ruleList[${vs.index}].ruleParameter[${assignments.index}].parameterValue" value="${asss.parameterValue}" /> ${asss.parameterValue}</td>
<td><input type="text" name="Name" value=""size="2"height="0.01">
<select style="width: 80px;">
<option value="">--Select--</option>
<c:forEach items="${targetlist}" var="target">
<option value="${target.displayName}"/>
<c:out value="${target.displayName}" />
</c:forEach>
</select>
</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<br>
<input type="submit" value="create">
</form:form>
<div>
<form action="/submitrule" method="post" model="command">
<table>
<tr>
<td colspan="6" align="right">
<select name="Id">
<option value="">--Select--</option>
<c:forEach items="${listRules}" var="rule">
<option>
<c:out value="${rule.id}" />
</option>
</c:forEach>
</select>
<input type="submit" value ="add"></td>
</tr></table></form>
</div>
Controller
#RequestMapping(value = "/submitrule", method = RequestMethod.POST)
public String addruleSerch(#ModelAttribute ("SpringWeb") Rule obj2, ModelMap model) {
model.addAttribute("Id", obj2.getId());
Rule rul = ruleApi.getRule(obj2.getId());
ArrayList<Rule> rl1 = new ArrayList<Rule>();
List<RuleParameter> ptr2 = rul.getRuleParameter();
Iterator it = ptr2.iterator();
while(it.hasNext()) {
RuleParameter r = (RuleParameter) it.next();
System.out.println(r.getParameterName());
System.out.println(r.getParameterValue());
}
rl1.add(rul);
model.addAttribute("ruleList", rl1);
return "hello";
}
How to add multiple column?
Thank you in advance for help/suggestions.

Dispay data from database to textbox asp.net mvc

How will I properly display data from database to textbox when the button "search" is clicked? It should display the item name and the price of that product code
enter image description here
Controller
public ActionResult Index(string searchString)
{
using(MyDatabaseEntities db = new MyDatabaseEntities())
{
var products = from s in db.Products
select s;
if (!String.IsNullOrEmpty(searchString))
{
products = products.Where(s => s.ProductCode.Equals(searchString));
}
return View(products.ToList());
}
}
Index
<div class="form-group">
<table style="text-align:left; margin-bottom:10px;">
<tr>
<td>Item Code</td>
<td>#Html.TextBox("SearchString")
</td>
<tr style="background-color:lightgray;">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="btn btn-block btn-info"id="buttonsearch" value="Search" />
</td>
</tr>
<tr>
<td> </td>
</tr>
#foreach (var item in Model) {
<tr>
<td style="text-align:left;">Item Name</td
<td>#Html.DisplayFor(modelItem=> item.ProductName)</td>
</tr>
<tr>
<td>Unit Price</td>
<td style="text-align:right;">#Html.DisplayFor(modelItem => item.Price)</td>
</tr>
}
<tr>
<td style="text-align:left;">Quantity</td>
<td>
<input type="text" id="quantity" class="input-sm" />
<span class="error">Product Name required</span>
</td>
</tr>
<tr>
<td style="text-align:left;">Discount</td>
<td>
<input type="text" id="discount" class="input-sm" style="text-align:right;" placeholder="0.00" />
<span class="error">Product Name required</span>
</td>
</tr>
</table>
</div>
Instead of .ToList() use .FirstOrDefault(); just in case you want to populate one record in your textbox.

Thymeleaf - Conditional Attributes only showing for a split second in html

i am working on a spring web application. i tried to write a function that checks whether if the entered password is correct.
this is the code from my controller:
#RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView loginUser(#ModelAttribute User user) throws FileNotFoundException {
if (patient.getPasswort().equals(patient.getPasswortConfirm())) {
Service.login(user);
ModelAndView modelAndView = new ModelAndView("mainpage");
modelAndView.addObject("user", user);
return modelAndView;
} else {
ModelAndView modelAndView = new ModelAndView("login");
modelAndView.addObject("wrongpw", true);
return modelAndView;
}
}
this is the code from the html page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="shortcut icon" type="image/ico" href="image/favicon.ico" />
<meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" />
<script src="lib/jquery-2.1.4.js"></script>
</head>
<body>
<div id="menuebg"></div>
<p th:if="${wrongpw}"><font color="red">Password is wrong</font></p>
<div id="menue">
<form action="01erstellen" method="post" th:object="${patient}">
<table border="0px">
<tr height="20px">
<td>Name: <input th:field="*{nachname}" onchange="nameLive();" type="text" id="txtName" value="" />
</td>
</tr>
<tr height="20px">
<td>Vorname: <input th:field="*{vorname}" onchange="vornameLive();" type="text" id="txtVorname" value="" />
</td>
</tr>
<tr height="20px">
<td>Email: <input th:field="*{email}" type="text" />
</td>
</tr>
<tr height="20px">
<td><label for="gebdat"> Geburtsdatum: <input th:field="*{geburtstag}" type="date" id="gebdat" />
</label></td>
</tr>
<tr height="20px">
<td><label for="passwd">Passwort: <input th:field="*{passwort}" type="password" id="passwd" size="20" maxlength="40" />
</label></td>
</tr>
<tr height="20px">
<td><label for="passwd-confirm">Wiederholen: <input th:field="*{passwortConfirm}"
type="password" id="passwd-confirm" size="20" maxlength="40" />
</label></td>
</tr>
<tr height="20px">
<td></td>
</tr>
<tr height="20px">
<td>
<br/>
<input id="btn-send" type="submit" value="Finish" />
</td>
</tr>
<tr height="20px">
<td></td>
</tr>
</table>
</form>
</div>
</body>
</html>
my problem is that if i type in a wrong password the text only shows for a split second an then disappears.
can someone help me?
thank you!