Un-editable input field - html

I have got a small code here in which i want to give a particular name and the text filed must be un-editable, how could that be done
<form method="get" action="watermark.php">
<center><h3>YGG Live Player Stats</h3></center>
<h5>Enter Player name :<h5> <br/><br/><input type="text" name="user" size=50 maxlength=50><br/><br/>
<input type="Submit" name="Search" value="user">
</form>

Assuming it's input field you want made readonly, use the readonly attribute:
<input type="text" name="user" size=50 maxlength=50 readonly>
See the W3 Schools page on the readonly attribute for more information.

Yes you can do your work with readonly
<input type="Submit" name="Search" value="user" readonly>
Your input field text can only changed by Programming language you use or by javascript. User can't alter it.

Related

Form submission minor issue

I have a form like this. I want to know that will the form submission work if the is placed in the middle of the text fields?
For example:
<input type="text" name="fname"> // First Name
<input type="text" name="lname"> // Last Name
<form method="post" action=""> // Post
<input type="text" name="username"> // Username
<input type="text" name="password"> // Password
<input type="submit" value="Submit"> // Submit Button
Will the submission work for First Name and Last Name field as the is after them so they do not come inside the form.
Your form elements (like your input boxes) have to be between an opening <form> and a closing </form> tag. So your fname and lname will be ignored. (Your closing </form> is missing, too.)
Why do you have to add your form elements between form tags? This allows you to add multiple forms to one page. To identify which element contains to which form, they have to be between the form tags.
Example "Login & register on the same site":
<form method="POST" action="login.php">
User: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>
<form method="POST" action="register.php">
Mail: <input type="text" name="email">
User: <input type="username" name="username">
Password: <input type="password" name="password">
Repeat password: <input type="password" name="pwdagain">
<input type="submit" value="Register">
</form>
Refer this site for further information: http://www.w3schools.com/html/html_forms.asp
First name and last name will not post. Username and password will post but u have to close form tag first.
If you transform you code like this it will post all :
<input type="text" name="fname" form="my_form_id"> // First Name
<input type="text" name="lname" form="my_form_id"> // Last Name
<form id="my_form_id" method="post" action="#"> // Post
<input type="text" name="username"> // Username
<input type="text" name="password"> // Password
<input type="submit" value="Submit"> // Submit Button
</form>
#shubham-jha If you want multiple submit buttons under a single form, you may use AJAX.
Create a JavaScript function on click, decide to which URL you want to send this data and then change form action using jQuery, then submit using JavaScript.
Jquery to change form action
There is some news on this front, it seems.
MDN has this for you to review
form HTML5
"The form element that the input element is associated with (its form owner). The value of the attribute must be an id of an element in the same document. If this attribute is not specified, this element must be a descendant of an element. This attribute enables you to place elements anywhere within a document, not just as descendants of their form elements."
Perhaps you can still achieve what you wished for. Only question then, is what browser support you must have.

Unable to obtain text box value (html) in jsp

<form name="myForm" action="MyServlet" method="POST">
Please enter your search query here:<br>
<input type="search" name="searchText" id="searchText" size="100" autocomplete="on" />
<input type="submit" name="search" value="Search" />
<textarea cols="30" rows="10">Result will be displayed here</textarea>
Click here if result not displayed for your search query.
</form>
In my servlet
arg = request.getParameter("searchText");
out.println(arg);
But I am getting the output as null.
It should be
<input type="text" name="searchText" .../>
The search type is used for search fields (a search field behaves like a regular text field).
please refer this link http://www.jguru.com/faq/view.jsp?EID=1297854 better you can change the name of the id and try or remove it and try

How to use "form=form_id" attribute in html5 input

I'm trying to use "form" attribute for html5 input as described here:
[1] http://www.w3schools.com/html5/att_input_form.asp
[2] http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_input_form
The description of the attribute says that form attribute:
"Specifies a space-separated list of id's to one or more forms the element belongs to"
I'm testing this by using the code below in W3C's TryIt editor (link 2 above)
<form action="demo_form.asp" id="form1">
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>
<form action="demo_form.asp" id="form2">
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>
Last name: <input type="text" name="lname" form="form1 form2" />
I supplied "string_for_form2" in form2 and "lastname" in the lname field. I'm getting the output as:
fname=string_for_form2
instead of
fname=string_for_form2&lname=lastname
Any ideas why the result is not as expected ? I've tried on Firefox 17 and Chrome 23.
Thanks
Because you're trying to assign two form owners.
"A form-associated element is, by default, associated with its nearest ancestor form element (as described below), but may have a form attribute specified to override this."
http://www.w3.org/TR/html5/forms.html#association-of-controls-and-forms
This attribute just allows markup flexibility, it doesn't change the form ownership paradigm from the previous spec.
I could not find anything in the W3C HTML5 specification to support the statement on the www.w3schools.com site that input element can belong to 2 or more forms. The input element's owner is always mentioned in singular and never as a list.
Furthermore on developer.mozilla.org there is explicit statement about the input association with one form only. The description of the form attribute states:
form: A string indicating which element this input is part of.
An input can only be in one form.
An input field can only be on one form. It is better to include it within the form scope, for clarity.
Use also name instead of only id on your forms. Although html5 supports it, what with older browsers? What with IE?
<form action="demo_form.asp" name="form1" id="form1">
<form action="demo_form.asp" name="form2" id="form2">
use javascript and name form on submit
<form action="demo_form.asp" onsubmit= 'this.id="form1"'>
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>
<form action="demo_form.asp" onsubmit= 'this.id="form1"'>
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>
Last name: <input type="text" name="lname" form="form1" />

No 'Save Password' Prompt by any browser for my form

My form is attached below, and I have tried many things I've found in other forums, but to no avail. I cant get the browser to prompt a 'Save Password'. Where am I going wrong. Hope someone can help. Thanks.
<form id="frmlogin" action="/index" method="post" enctype="application/x-www-form-urlencoded" autocomplete="on">
<label id="landing_username" class="required" for="username">Username/Email</label>
<input id="landing_username" name="username" type="text" value="" name="username" />
<label id="landing_password" class="required" for="password">Password</label>
<input id="landing_password" name="password" type="password" value="" name="password" />
<submit id="loginbtn" onclick="LoginFun()" type="submit" name="loginbtn">Login</submit>
</form>
Try to clean the HTML a bit, maybe it helps:
<form id="frmlogin" action="/index" method="post">
<label id="landing_username" class="required" for="username">Username/Email</label>
<input id="username" name="username" type="text" />
<label id="landing_password" class="required" for="password">Password</label>
<input id="password" name="password" type="password" />
<input id="loginbtn" onclick="LoginFun()" type="submit" name="loginbtn" value="Login" />
</form>
the form attribute enctype is by default application/x-www-form-urlencoded so you don't need to specify it
the labels for attribute should contain the id, not the name of the associated input
element IDs should be unique
the attribute name is defined twice for both password and username
the attribute autocomplete is by default on
the input value is not required, so you don't need to add it to the inputs with an empty string
the submit button should be an input of type submit
Some of these changes are only optimizations and the code could work fine without them, but others, such as ensuring the unique id of each tag, are fixes and they are strongly recommended even if the browser displays the form properly.

pass form input value to action

I have a page (module-access.php).
On the page I have a form with one text input field. I'd like to set whatever is typed in this field to be part of the form's action.
<form action="module-access.php?company=THE-USERS-INPUT" method="post" name="company" id="company">
Company Name: <input type="text" name="textfield" id="textfield">
<INPUT TYPE="submit" name="submit" VALUE="Go"></FORM>
Thanks
Just change the input name from textfield to company and the action type to GET
<form id="myform" action="module-access.php" method="GET">
Company Name: <input type="text" name="company" id="company">
<input type="submit" name="submit" value="Go">
</form>
Why? Does it matter whether it's passed in the POST or GET? You can always just use REQUEST.
If it does matter then you'll need to use JavaScript to modify the action before you POST the form. Not very hard to do.