Enable autocomplete in HTML form using <script>? - html

I got a form where I'm not allowed to edit the form directly. However I'm able to add etc. Is it possible to add autocomplete="off"-attribute without editing directly into the form?
This is my form:
<form action="/action_page.php">
<input type="text" name="firstname">
<input type="submit" value="Submit">
</form>
Hope that was understandable.

I suggest you to use <button> for the submit instead of <input> and give the tag an id .
Try this javascript:
function off_ac(){
document.getElementById('text_input').autocomplete = 'off';
}
<form action="/action_page.php">
<input id="text_input" type="text" name="firstname">
<input type="submit" value="Submit">
</form>

Autocomplete will be overruled by most browsers. A workaround is to change the text Field to text area. Set it to one row high and x letter Width, and it will look almost like a text Field.

Related

HTML Submit button don't work

I recently started HTML and made my first Website. I made bunch of lines of codes, and the last line is: <input type="submit" name="register" value="Register" action="Registered.html">. I wanted to this submit button named as "Register" to get me to the my "Registered.html" file but something isn't right. The button shows up, and it's valued as "Register" but `action="Registered.html" doesn't work. I hope you understand me, if you can, fix this for me.
The form element takes the action attribute, not the input:
<form action="Registered.html">
<input type="submit" name="register" value="Register">
</form>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
notice the action is at the form..
refer https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit
In general form elements are used to send data to a server. It wraps around the elements which specifies the data, input or button elements, for instance. If you add a name and a value attribute to your input and button elements, you will send this name-value-pair to your server.
If you don’t need to send any (additional) data to your server, just use anchor elements:
Register
<form>
<input type="submit" formaction="Registered.html" value="Register">
</form>
The formaction attribute of the input tag is not supported in Internet Explorer 9 and earlier versions.

Two forms on one page causes wrong validation

I have one page with two separate forms. Most input fields are required. When I click the submit button on the second form, it asks me to fill out the required fields in the first form.
How do I make sure that it only validates the form in which I clicked the submit button?
<form method="post" action="index.php" name="orderQuick" id="orderQuick">
<input type="text" name="street" id="street" required>
<button type="submit" name="submitBtn" id="submitBtn">Submit</button>
</form>
<form method="post" action="index.php" name="order" id="order">
<input type="text" name="street2" id="street2" required>
<button type="submit" name="submitBtn2" id="submitBtn2">Submit</button>
</form>
I think it is because you have not closed <button> tag so it is considering both input type in one form. Close <button> tag.I think it will solve your issue.
I think you will need to use the jqueryvalidation plugin: (http://jqueryvalidation.org/valid/)
Using this plugin, on the click of the respective submit buttons, you just need to call the method:
$("#orderQuick").valid();
and
$("#order").valid();
This should solve your issue.

Do not show previous input in html textarea

This question is very basic and simple.
How can I make it where the textarea will not show previous input.
<form action="" method="post">
<textarea> Person's input </textarea>
<input type="submit" name="submit" value="post">
</form>
After using the textarea a few times I started noticing the previous input I've entered. Is there any way to get rid of that?
You can set the autocomplete attribute of an input tag to off to prevent the browser from showing the previous inputs.
<input type="text" autocomplete="off" />
And for textarea
<textarea autocomplete="off">text</textarea>
You can also use autocomplete for a complete form.

How can I make an html button that passes a parameter?

I want a html button with parameter functionality.
new/?sorting=desc is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.
<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>
I want buttons that behave like these links:
Äldst först
Nyast först
If you want something to act as a link, then you should use a link.
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
You need to store the data in hidden inputs.
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
If you are using jQuery, you can use the code below.
This will fill a hidden input with the correct value when you click on one of the submit buttons.
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?

How to prevent a form with GET method from sending the value of the submit button?

I have a simple form:
<form action="/search" method="get">
<input type="text" name="q" value="">
<input type="submit" name="search" value="search">
</form>
When submitting the url becomes `/search?q=Loremipsum&search=search
I really don't want that last bit, this seems pretty common problem and think it could be solved without js, but I realized that even google.com has this problem when you click on the search button. (maybe they don't care much about ugly urls?)
search?hl=en&source=hp&q=Loremipsum&btnG=Google+Search&aq=f&..
Is there a way to prevent the value of the submit button to be excluded without javascript?
I see in Stack overflow the search is ?q= but they don't have a submit button.
You can omit name attribute in the final input like this:
<form action="/search" method="get">
<input type="text" name="q" value="">
<input type="submit" value="search">
</form>
Should do the trick. Keeping value attribute allows you to manipulate what text is displayed on the button.
For the record, you can also omit the submit button if you like, and the form will submit when you press return after typing your search term. (This is how the Stack Overflow search box works).