How to make input box big as text area in html - html

I have to show the a new quote in the input box. The input box is too small.
<form action="https://twitter.com/intent/tweet" method="get" id=usrform>
<div id="input">
<label for=quote>New Quote will appear</label><br>
<input name="text" id="quote" type="text" value="" multiple="multiple">
</div>
<button id=getquotebtn type=button>Get A New Quote</button>
<button id=twitterbtn type=submit>tweet</button>
</form>

<form action="https://twitter.com/intent/tweet" method="get" id=usrform>
<div id="input">
<label for=quote>New Quote will appear</label><br>
<textarea name="text" id="quote" type="text" value="" cols="5" rows="5">your quote is here</textarea>
</div>
<button id=getquotebtn type=button>Get A New Quote</button>
<button id=twitterbtn type=submit>tweet</button>
</form>
Please use textarea instead of the input type text. This is the good practice

For an input that allows a person to type multiple lines, use <textarea>. You can also define the cols and rows the textarea can have, basically creating new lines at that point

Option 1:
$("document").ready(function(){
$("#getquotebtn").click(function(){
setInput("hello world ") //
})
})
function setInput(val){
//alert()
$("#quote").val(val)
$("#quote").css("width", (val.length * 6) +"px"); //dynamically set the width length of input element
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="https://twitter.com/intent/tweet" method="get" id=usrform>
<div id="input">
<label for=quote>New Quote will appear</label><br>
<input name="text" id="quote" type="text" value="" multiple="multiple">
</div>
<button id=getquotebtn type=button>Get A New Quote</button>
<button id=twitterbtn type=submit>tweet</button>
</form>
Option 2:
$("document").ready(function(){
$("#getquotebtn").click(function(){
setInput("hello world")
})
})
function setInput(val){
$ ("#quote").val(val)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="https://twitter.com/intent/tweet" method="get" id=usrform>
<div id="input">
<label for=quote>New Quote will appear</label><br>
<textarea name="text" id="quote" type="text" value="" multiple="multiple"> </textarea>
</div>
<button id=getquotebtn type=button>Get A New Quote</button>
<button id=twitterbtn type=submit>tweet</button>
</form>

Related

why can't I submit an empty textbox to the server

when I click the 'save new post' button and the title and body content are provided then the action of sending a request is successfull, but if I leave one field blank, than the request isn't even made.
this is my code:
<form action="/create-post" method="POST">
<div class="form-group">
<label for="post-title" class="text-muted mb-1"><small>Title</small></label>
<input required name="title" id="post-title" class="form-control form-control-lg form-control-title" type="text" placeholder="" autocomplete="off">
</div>
<div class="form-group">
<label for="post-body" class="text-muted mb-1"><small>Body Content</small></label>
<textarea required name="body" id="post-body" class="body-content tall-textarea form-control" type="text"></textarea>
</div>
<button class="btn btn-primary">Save New Post</button>
</form>
And this is what I get when I leave a field blank:
form behavor after submitting empty field
in the image, 'Compila questo campo' just means 'Fill in this field'
Edit:
thank you for reminding me that it’s because of the required field, but then why is that in this example i can't submit if the title field is empty but can if the body is empty?
<form class="mt-3" action="/post/<%= post._id %>/edit" method="POST">
<div class="form-group">
<label for="post-title" class="text-muted mb-1"><small>Title</small></label>
<input required name="title" value="<%= post.title %>" id="post-title" class="form-control form-control-lg form-control-title" type="text" placeholder="" autocomplete="off">
</div>
<div class="form-group">
<label for="post-body" class="text-muted mb-1"><small>Body Content</small></label>
<textarea required name="body" id="post-body" class="body-content tall-textarea form-control" type="text"><%= post.body %>
</textarea>
</div>
<button class="btn btn-primary">Save Changes</button>
Note that this is a ejs template, so that's why it as <% and <%=
You have required attribute both of your inputs. So you can't submit this form in this way.
See here for details
For example in this example you can submit the form:
<!DOCTYPE html>
<html>
<body>
<h1>The button type attribute</h1>
<form action="#" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</body>
</html>
But in this example you can't:
<!DOCTYPE html>
<html>
<body>
<h1>The button type attribute</h1>
<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" required><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" required><br><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</body>
</html>
Good luck.
You explicitly said that the user was required to fill in a value.
Don't do that if the field is optional.
Because your <input> and <textarea> tags have required attribute. Remove that attribute if you want to make them optional.
You are using required attribute with textbox and text area.
The required attribute is a boolean attribute.
When present, it specifies that an input field must be filled out before submitting the form.
This is client side (browser side validation).
Reference

How to concatenate a user inputted string using HTML input tag

I am doing the following:
<form action="https://www.google.com/search">
<div>
<input type="text" name="q" id="corners">
</div>
<div>
<input type="submit" value="Google Image Search">
</div>
</form>
However, I want to add additional default text to the URL after the user's input like this:
https://www.google.com/search?q=searchterm&some-additional-text
How can I do this?
The following code uses JavaScript to concatenate https://www.google.com/search?q=, the input value and any additional text, then assigns that string to the action attribute of the form, before submitting the form.
function submitForm() {
var form = document.getElementById("form");
var search = document.getElementById("corners").value;
var additional = "&";
form.setAttribute("action", "https://www.google.com/search?q=" + search + additional);
form.submit();
}
<form action="https://www.google.com/search" id="form">
<div>
<input type="text" name="q" id="corners">
</div>
<div>
<input type="button" value="Google Image Search" onclick="submitForm()">
</div>
</form>
I ended up just using the following:
<div>
<input type="hidden" name="test" value="test" style="display: none;">
<input type="text" name="test">
</div>

Can I submit form by clicking label?

I have a code that submits form by clicking <input type="submit">, and I want to change my form to submit when label, which is outside of the form, is clicked.
What should I do?
Here's my code:
<div class="join">
<p>Join</p>
<span>Join to access all features of the site!</span>
</div>
<form action="join/joinf" method="POST" class="joinform">
<div class="left">
<p>ID<span class="required"> *required</span></p>
<p>PW<span class="required"> *required</span></p>
</div>
<div class="right">
<p><input type="text" name="id" id="id" required>
<p><input type="password" name="pw" required></p>
</div>
<input type="submit" id="formsub" value="join">
</form>
<label for="formsub"><button>join-label</button></label>
Try using Jquery click element, set id for label .
$('#LabelId').click(function(e) {
e.preventDefault();
$("#formsub").submit();
});

Validation of angular form without submit button

I am using anuglar.js form validation.
I want to check validation without form submit button.
This is my html.
<form name="userForm">
<input type="hidden" ng-model="StandardID" />
<div class="form-group">
<label for="email">Name:</label>
<input type="text" class="form-control" ng-model="Name" placeholder="Name" maxlength="50" required>
<span ng-show="userForm.Name.$dirty && !userForm.Name.$valid">Name is required.</span>
</div>
<div class="form-group">
<label for="pwd">Alias:</label>
<input type="text" class="form-control" ng-model="Alias" placeholder="Alias" maxlength="50" required>
</div>
<button type="submit" class="btn btn-info" ng-click="update()">Submit</button>
<button type="submit" class="btn btn-info" data-dismiss="modal">Cancel</button>
</form>
My controller js is.
$scope.update= function () {
alert($scope.userForm.Name.$valid);
if ($scope.userForm.Name.$valid) {
alert("Entry added");
}
}
It shows small dialog that says this field is required. I don't want this popup . Why span section does not show?
To do it, the key is use the name attribute in your <form> and in all of your inputs.
Following this way, angularjs will create a form instance where you can access all fields like myForm.myInput.$invalid
For example:
<form name="myForm" novalidate>
<label>My Input:</label>
<input type="text" name="myInput" ng-model="myInput" required>
<span ng-show="myForm.myInput.$dirty && myForm.myInput.$invalid">My Input is invalid.</span>
</form>
Check angular docs
HTML
<div ng-app="myApp">
<form name="cutome_form" ng-submit="submitForm()" novalidate>
<input type="text" name="name" class="form-control" ng-model="Name" placeholder="Name" maxlength="50" required>
<div ng-show="cutome_form.name.$dirty && cutome_form.name.$invalid">
<span class="error" ng-show="cutome_form.name.$error.required">The field is required.</span>
</div>
<div class="form-group">
<label for="pwd">Alias:</label>
<input type="text" name="alias" class="form-control" ng-model="Alias" placeholder="Alias" maxlength="50" required>
</div>
<div ng-show="cutome_form.alias.$dirty && cutome_form.alias.$invalid">
<span class="error" ng-show="cutome_form.alias.$error.required">The field is required.</span>
</div>
<button type="submit" ng-disabled="cutome_form.$invalid">Submit All</button>
</form>
</div>
directive
.directive('ngModel', function() {
return {
require: 'ngModel',
link: function(scope, elem, attr, ngModel) {
elem.on('blur', function() {
ngModel.$dirty = true;
scope.$apply();
});
ngModel.$viewChangeListeners.push(function() {
ngModel.$dirty = false;
});
scope.$on('$destroy', function() {
elem.off('blur');
});
}
}
});

Input with multiline

I am using this code to show a textbox and a button:
<html>
<body>
<form name="form" method="post">
<input type="text" name="text_box" size="50"/>
<input type="submit" id="search-submit" value="submit" />
</form>
</body>
</html>
How can I make the input to be with multiline?
The best way to have a multiline input is to use a textarea:
<textarea name='multiline_ip' rows='5' cols='15'></textarea>