auto complete attibute not working in HTML - html

I have input box with email address. It should not be auto complete but even after added autocomplete="off" in input box. Its showing auto complete values.

it is probably found in chrome...but you can try
in form tag add autocomplete="off" autocomplete="false" autofill="off"
and then add following code after form opens...
<input type="text" name="usernamefake" style="display:none;">
<input type="password" name="fakepassword" style="display:none;">
<!-- from here now your all input fields...below-->
If your problem doesn't get solve with above solution, you can add one more hidden fake input field just above your actual email input field and have a try...
Update :
you can try
<input type="text" name="email" readonly onfocus="if (this.hasAttribute('readonly')) {
this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
this.blur(); this.focus(); is for mobile screens to show keyboard after readonly attribute is removed..by js
EXAMPLE CODE :
div{
padding:10px;
margin:20px;
}
input {
padding:5px;
margin:5px;
}
<div>
<form autocomplete="off">
<label for="email">E-Mail</label>
<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
<br/>
<label for="pw">Password</label>
<input id="pw" readonly type="password" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
<br/>
<input type="submit" value="Go!" />
</form>
</div>

Related

Focus onto next input on Enter key using jQuery script

I'm using this jQuery script to focus onto next input when enter pressed:
$(function() {
$(".form >input").on('keyup', function(e) {
if (e.which === 13) {
$(this).next('input').focus();
}
});
});
It does work with this basic skinny HTML form
<div class="form">
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
</div>
But not with this one
<div class="form">
<input name="cislo1" type="text" class=cislo1 placeholder="" id="cislo1" autofocus /><br>
<input name="cislo2" type="text" class=cislo2 placeholder="" id="cislo2" /><br>
<input name="cislo3" type="text" class=cislo3 placeholder="" id="cislo3" /><br>
<input name="cislo4" type="text" class=cislo4 placeholder="" id="cislo4" /><br>
<input name="cislo5" type="text" class=cislo5 placeholder="" id="cislo5" /><br>
<input name="cislo6" type="text" class=cislo6 placeholder="" id="cislo6" /><br>
<input name="cislo7" type="text" class=cislo7 placeholder="" id="cislo7" /><br>
<input name="cislo8" type="text" class=cislo8 placeholder="" id="cislo8" /><br>
<input name="cislo9" type="text" class=cislo9 placeholder="" id="cislo9" /><br>
<input name="cislo10" type="text" class=cislo10 placeholder="" id="cislo10" /><br>
<input name="cislo11" type="text" class=cislo11 placeholder="" id="cislo11" /><br>
</div>
What seems to be the problem here? Help me please, I'm stuck
The issue here is you are using direct child selector like:
$(".form > input")
This only matches any direct input element inside form class, but in your next example input is not the direct child. So, you need to descent sector instead like:
$(".form input")
This will match any input inside the form class where it is a direct child or not.
Also, you need to replace
$(this).next('input').focus();
with this:
$(this).nextAll('input:first').focus();
This is needed because .next() will get the immediately following sibling of each element, but here input is not the immediate sibling. We also have some <br> in between which are causing the issue. This can be resolved using .nextAll('input:first') instead.
Demo:
$(function() {
$(".form input").on('keyup', function(e) {
if (e.which === 13) {
$(this).nextAll('input:first').focus();
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form">
<p class="cislo">
<input name="cislo1" type="text" class=cislo1 placeholder="" id="cislo1" autofocus onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo1.value=cislo1.value.slice(0,2)" /><br>
<input name="cislo2" type="text" class=cislo2 placeholder="" id="cislo2" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo2.value=cislo2.value.slice(0,2)" /><br>
<input name="cislo3" type="text" class=cislo3 placeholder="" id="cislo3" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo3.value=cislo3.value.slice(0,2)" /><br>
<input name="cislo4" type="text" class=cislo4 placeholder="" id="cislo4" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo4.value=cislo4.value.slice(0,2)" /><br>
</p>
</div>

HTML Form is submitted without to be populated on iOS devices

I have simple html form on my site:
<form action="mailer.php" method="post">
<fieldset>
<div class="column-50">
<div>
<label for="name">Name <span>*</span></label>
<input type="text" id="name" name="name" required>
<span class="mf-error-message">Error! </span>
</div>
<div>
<label for="email">Email <span>*</span></label>
<input type="text" id="email" name="email" required>
<span class="mf-error-message">Error! </span>
</div>
.... // some more fields
<input type="submit" id="submit" name="submit" value="Enter your Information">
</form>
The problem is that on iOS devices ( phone, tablet .. ) form it can be submitted without user to populate required fields.
Why is that? Is there a way to fix it on client side?
This should work. But it will be for all not only for iOS
<form action="mailer.php" method="post" id="myForm">
Then this
var form = document.getElementById('myForm');
form.noValidate = true;
form.addEventListener('submit', function(event) {
if (!event.target.checkValidity()) {
event.preventDefault();
alert('Error! You must fill all required fields.');
}
}, false);

Enable the number keyboard in touch device without using input types

I want to trigger the number keypad, email keypad and tel keypad in all touch devices without using any input types.
<input type="text" value="" class="text-box number">
<input type="text" value="" class="text-box email">
<input type="text" value="" class="text-box tel">
if it possible through jquery also fine.
Due our comments in the main post, the only choice is javascript.
According with your original HTML:
<input type="text" value="" class="text-box number">
<input type="text" value="" class="text-box email">
<input type="text" value="" class="text-box tel">
I can make some changes (for example, add a data-type custom attribute, see the following HTML) and then the javascript block:
$(document).ready(function() {
// iteration through all elements that matches
$('.text-box[data-type]').each(function() {
//replace the type
$(this).attr('type', $(this).attr('data-type'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<input type="text" value="" data-type="number" class="text-box">
<input type="text" value="" data-type="email" class="text-box">
<input type="text" value="" data-type="tel" class="text-box">
This will not work in IE9 or less since it doesn't allow to change dynamically the type of an input, but in the rest of browsers it will work perfectly.

Form submitting with empty required fields due to use of "placeholder="

My form is tripping up with required fields are able to be submitted without entering anything in the field. I'd like to use placeholder text but it must be reading this as a value, hence the form goes through?
I'm using the html 5 'placeholder' and 'required attributes. email address does get flagged as the placeholder text doesnt match the format i think.
Is there any way to get the form to flag the other required fields?
<form action="FormToEmail.php" method="POST" name="Competition">
<div id="text">
<input class="field" value="" type="text" name="Name" required placeholder="FULL NAME*">
<input class="field" value="" type="email" name="Email" required placeholder="EMAIL ADDRESS*">
<input class="field" value="" type="text" name="Contact-number" required placeholder="CONTACT NUMBER*">
<input class="field" value="" type="text" name="Code" required placeholder="UNIQUE CODE*">
<p>I have read the Terms and Conditions</p><input type="checkbox" name="Terms and Conditions" value="Selected" required></div>
<p >Read the Terms and Conditions.</p>
<p>* required field</p>
<input class="btn btn-draw" type="submit" name="submit" value="Submit!" />
</form>
EDIT: i recall now that i'm using the javascript below to show the placeholder text in older versions of internet explorer. This script does work for that with the knock on effect of the empty fields submitting.
I am probably best covered to leave it like this, but i'd be interested if there is any comprehensive solution to ensure placeholder text shows in older browsers and the empty fields are flagged.
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
Ok, you need to prevent the form submit if the input val is equal the placeholder:
}).blur().parents('form').submit(function(event) {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() === input.attr('placeholder')) {
event.preventDefault();
input.val('');
}
Are you using any plugin? In which browser is the problem?
The test don't show any problems.
https://jsfiddle.net/mcymnayz/
<form action="FormToEmail.php" method="POST" name="Competition">
<div id="text">
<input class="field" value="" type="text" name="Name" required placeholder="FULL NAME*">
<input class="field" value="" type="email" name="Email" required placeholder="EMAIL ADDRESS*">
<input class="field" value="" type="text" name="Contact-number" required placeholder="CONTACT NUMBER*">
<input class="field" value="" type="text" name="Code" required placeholder="UNIQUE CODE*">
<p>I have read the Terms and Conditions</p><input type="checkbox" name="Terms and Conditions" value="Selected" required>
</div>
<p >Read the Terms and Conditions.</p>
<p>* required field</p>
<input class="btn btn-draw" type="submit" name="submit" value="Submit!" />
</form>

Required form field not working

I've got a form with required fields, but it allows me to submit the form without a value in required fields. What would be the best way to validate this?
<form action="formmail.php" method="post" id="orderform" onsubmit="formmail.php">
<input name="company" id="company" type="text" class="orderFormFields" placeholder="Company Name" />
<input name="name" id="name" type="text" class="orderFormFields" placeholder="Name" required/>
<input name="phone" id="phone" type="text" class="orderFormFields" placeholder="Phone" required/>
<input name="email" id="email" type="email" class="orderFormFields" placeholder="Email" required/>
<button class="formButton" type='submit' id='submit' value='Submit'/>
</form>
You can also use this in your stylesheet to hide the submit until the user provides valid input. Using this method will also insure that the person filling out you form uses an actual email (as opposed to just typing "asdf").
.orderFormFields {
border-color: #3c3c3c;
}
.orderFormFields:valid {
border-color: green;
}
Good luck =)