angularjs add white space in ng-model - angularjs-directive

I have this <input name="Name" type="text" id="Name" class="step-input" placeholder="NAME*" readonly="readonly" ng-model="(ContactPerson)+(ContactPersonSurname)" />
on the ng-model, it concatenates two fields and works fine, but i want to add space between (ContactPerson) and (ContactPersonSurname) using angular. How can I achieve that?

If you provide expressions inside ng-model directive you will get an [ngModel:nonassign] error, In Angularjs documentation they clearly states that
This error occurs when expression the ngModel directive is bound to is a non-assignable expression.
Always make sure that the expression bound via ngModel directive can be assigned to.
Solution:
Create a new $scope variable someting like
$scope.fullName = (ContactPerson)+ ' ' +(ContactPersonSurname); then use this in your html as below.
angular.module('mainApp', [])
.controller('mainCtrl', function ($scope) {
$scope.name = "john";
$scope.surName = "Doe";
$scope.fullName = $scope.name + " " + $scope.surName;
});
<html ng-app="mainApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body ng-controller="mainCtrl">
<input type="text" ng-model="fullName" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
</body>
</html>

Your input field is readonly. So you can use expressins instead of binding model.
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.ContactPerson = 'foo';
$scope.ContactPersonSurname = 'bar';
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<input name="Name" type="text" id="Name" class="step-input" readonly="readonly" value="{{ContactPerson}} {{ContactPersonSurname}}" />
</div>
</div>
Hope this solves your problem.

Related

Use of Input and Button in HTML

I am creating a webpage that redirects users to a specific webpage.
Some part of the URL of the specific webpage is constant and the rest is a variable.
If the webpage is www.gotop.com/page1. www.gotop.com/ is constant every time but the page1 part changes. And I want to take the page1 part as an input in my webpage and then a button to go to www.gotop.com/page1
I tried a lot but failed. My final code is
<!DOCTYPE html>
<html>
<label for="name">Name (4 to 8 characters):</label>
<input type="text" id="name" name="name" required
minlength="4" maxlength="8" size="10">
<body>
<h1>The button Element</h1>
<button type="button" onclick="window.location.href='http://152.158.53.1:2222/q/"name"/';">Click Me!</button>
<p>PLEASE WAIT...Redirecting to REALME 1 URL</p>
</body>
</html>
But it doesn't work.
Here I took the value of the variable part of URL from the input and concatenated it at the end of the constant part of the URL.
window.location.href redirects you to the desired URL.
This should help,
document.getElementById('button').addEventListener('click', function(e) {
const page = document.getElementById('val').value
window.location.href = `/constant/url/${page}`
})
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="val">
<button id="button">Click me!</button>
</body>
</html>
I think this would be a better solution
function loadPage(){
location.href = document.querySelector("#page_name").value;
}
<input type="text" id="page_name"/>
<button onclick="loadPage()">Go</button>
When the button is clicked, the loadPage function would be called. There, The value of the input is obtained and the page is redirected to that url.

HTA to get data from webpage to hta textbox

Using Hta i want data from web page to hta text Box. Below is the code which i am trying to create but i have no clue how to call data from web page to hta text box.
<html>
<head>
<title>My HTML Application</title>
<script language="vbscript">
urls=("https://www.99acres.com/shri-laxmi-celebration-residency-sector-2b-vasundhara-ghaziabad-npxid-r63907?src=NPSRP&sid=UiB8IFFTIHwgUyB8IzEjICB8IG5vaWRhIzUjIHwgQ1AxMiB8IFkgIzE4I3wgIHwgMTIgfCMzIyAgfCA3ICM1I3wgIHwgMjMgfCM0MyMgIHw=")
Sub RunLoop()
window.navigate urls
End Sub
</script>
</head>
<body>
<input type="button" value="Click" onclick="RunLoop">
Possession:
<input type="text" name="Possession" Value="">
Configurations:
<input type="text" name="Configurations" Value="">
New Booking Base Price:
<input type="text" name="New Booking Base Price" Value="">
</body>
</html>
The data which i require from webpage.
The output which i require in hta.
Using window.ActiveXObject("Microsoft.XMLHTTP"), we get the whole webpage and assign it to an invisible/hidden div (for simplicity). Note that this may result to unwanted styling because of the webpage's own global styling. A better way to do it is to open the webpage on a separate IE.
HTAs default engine is IE7 so we needed to insert meta http-equiv="x-ua-compatible" content="ie=9" in order to support the getElementsByClassName functionality because the data that we want to get from 99acres.com was referenced by class.
Copy the code below to notepad and save it as xxx.hta:
<html>
<head>
<meta http-equiv="x-ua-compatible" content="ie=9">
<title>My HTML Application</title>
<script language="javascript">
var url= "https://www.99acres.com/shri-laxmi-celebration-residency-sector-2b-vasundhara-ghaziabad-npxid-r63907?src=NPSRP&sid=UiB8IFFTIHwgUyB8IzEjICB8IG5vaWRhIzUjIHwgQ1AxMiB8IFkgIzE4I3wgIHwgMTIgfCMzIyAgfCA3ICM1I3wgIHwgMjMgfCM0MyMgIHw=";
var xmlHttp = new window.ActiveXObject("Microsoft.XMLHTTP");
function httpGet(theUrl){
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
function RunLoop() {
var data = httpGet(url);
document.getElementById("tempdiv").innerHTML = data;
document.getElementsByName("Possession")[0].value = document.getElementsByClassName("factVal1")[0].innerHTML;
document.getElementsByName("Configurations")[0].value = document.getElementsByClassName("factVal1")[1].innerHTML;
document.getElementsByName("New Booking Base Price")[0].value = document.getElementsByClassName("factValsecond")[0].innerHTML;
}
</script>
</head>
<body>
<input type="button" value="Click" onclick="javascript:RunLoop();">
Possession:
<input type="text" name="Possession" Value="">
Configurations:
<input type="text" name="Configurations" Value="">
New Booking Base Price:
<input type="text" name="New Booking Base Price" Value="">
<div id="tempdiv" style="display:none;visibility:hidden;height:0px">
</div>
</body>
</html>

How can I access a data submitted in a form which is saved as another file with nodejs without using any framework

I am new to Node.JS and I am trying to display the submitted data in a form which is stored as an html file using Node.JS. How can I do that?
I don't want to use any framework as I want to make my base stronger.
Here is my index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Sample Form with Node.JS and MongoDB</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="sample.js"></script>
</head>
<body>
<form method="POST" action="incoming" enctype="multipart/form-data">
<fieldset>
<legend>Sample Form</legend>
<p><input type="text" name="name" placeholder="Enter your Name"></p>
<p><input type="email" name="email" placeholder="Enter your Email"></p>
<p><input type="submit" name="submit"></p>
</fieldset>
</form>
</body>
</html>
And here is my sample.js
var http=require('http');
var qs=require('querystring');
var fs=require('fs')
var port=8000;
http.createServer(function(req,res){
if(req.method==="GET"){
fs.readFile('index.html',function(err,data){
res.writeHead(200,{'Content-Type':'text/html'});
res.write(data);
res.end();
});
}
else if(req.method==='POST'){
if(req.url==='/incoming'){
var reqbody='';
req.on('data',function(data){
reqbody+=data;
});
req.on('end',function (){
var formdata=qs.parse(reqbody);
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<fieldset><legend>Form Inputs</legend>');
res.write('Name: '+formdata.name);
res.write('Email: '+formdata.email);
res.end('</fieldset></body></html>');
});
}
}
}).listen(port);
Your help would be appreciated. Thank You in advance.
UPDATE
Removing the enctype somehow worked and now it's working just fine. Thanks
Just remove the enctype from index.html, I don't know why it worked but when I was fiddling with my code to make it work removing the enctype did the trick

How can I force AngularJS to serialize empty form fields

As far as I can tell, AngularJS does not serialize a form field if it is empty. But, I need this fields to be in the JSON that is generated, even if they are empty. I am trying to query that JSON, and it will fail if the fields descriptors are not there. Any tips on how to get AngularJS to do this?
In the example below, if you entered "John" into the name field, and nothing in the optionalval field, the json that is formed is this {name: John}. But I would like it to be like this {name:'John', optionalval:''}. This is in the case of a "create new" form where optional fields might not have any values. But, the fields need to be sent whether they have values or not.
<!doctype html>
<html>
<head>
<title>Serialize Test</title>
<script src="js/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.addnew = function(){
$http.put('/newthing.json', JSON.stringify($scope.item))
.success(function(){
})
.error(function(){
});
};
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<label for="name">Name:</label>
<input type="text" id="name" ng-model="item.name" required>
<label for="optionalval">Don't put anything here:</label>
<input type="text" id="optoinalval" ng-model="item.optionalval">
<button ng-click="addnew()">Serialize</button>
</body>
</html>
One way is to preinitialize model with empty string. For example, by setting model value in controller:
$scope.item = {optionalval: ''};
Here is a demo:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.item = {optionalval: ''};
$scope.addnew = function() {
$http.put('/newthing.json', JSON.stringify($scope.item))
.success(function() {})
.error(function() {});
};
});
<script src="https://code.angularjs.org/1.4.3/angular.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<label for="name">Name:</label>
<input type="text" id="name" ng-model="item.name" required>
<label for="optionalval">Don't put anything here:</label>
<input type="text" id="optionalval" ng-model="item.optionalval">
<button ng-click="addnew()">Serialize</button>
<pre>{{item | json}}
</div>

Placing Double Quotes Around Html Input Value

Heres my Code:
<form>
<input class="wrapped-input" type="text" id="blah blah" style="text-align:center" placeholder="(Enter your exact search term here)" name="exact_term" tabindex="5" required/>
</form>
I've ommitted a few things to make this form functional, however I would like to place double quotes AROUND any value the user enters into the html input field.
What's the best way to do this?
I went under the assumption that you wanted to wrap what the user submits in quotes rather than manipulating the textbox itself.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
$(document).ready(function() {
$('#btnSubmit').click(function() {
var userInput = $('#blah-blah').val()
alert('User input: "' + userInput + '"');
});
});
</script>
</head>
<body>
<form>
<input class="wrapped-input" type="text" id="blah-blah" style="text-align:center" placeholder="(Enter your exact search term here)" name="exact_term" tabindex="5" required/>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
</body>
</html>
You could use jQuery to manipulate the string before the form is submitted or you could just use string interpolation to add parentheses on the server side.
Here is a pure JavaScript version of what you want to do, because, well, screw jQuery.
var thing = document.getElementById('thing');
thing.addEventListener('keyup', function() {
if (!/^\"/.test(thing.value)) {
thing.value = '"' + this.value;
}
});
thing.addEventListener('blur', function() {
if (!/\"$/.test(thing.value)) {
thing.value = this.value + '"';
}
});