Is it possible to change the content HTML5 alert messages? [duplicate] - html

This question already has answers here:
How to set custom validation messages for HTML forms?
(17 answers)
Set custom HTML5 required field validation message
(12 answers)
Closed 8 years ago.
Is it possible to control HTML5 alert messages? when adding 'required' to an input field.
because I want it to be specific and I don't want it's language to depend on the browsers.
<input id="answer" required>

You can use customValidity
$(function(){
var elements = document.getElementsByTagName("input");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("This can't be left blank!");
};
}
});
I think that will work on at least Chrome and FF, I'm not sure about other browsers

Thank you guys for the help,
When I asked at first I didn't think it's even possible, but after your answers I googled and found this amazing tutorial:
http://blog.thomaslebrun.net/2011/11/html-5-how-to-customize-the-error-message-for-a-required-field/#.UsNN1BYrh2M

Yes:
<input required title="Enter something OR ELSE." />
The title attribute will be used to notify the user of a problem.

Related

"this" is not recognizing in react's input for getting value [duplicate]

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
Closed 2 years ago.
I never understood how that this works if it ever works
in my react I wrote <input onChange={()=>console.log(this.value)} /> Why doesn't it recognize this??? it tells me that it Cannot read property 'value' of undefined
onChange anyone help please :/
React doesn't bind the event listener with the element.
So, the this refers to the class Component in which its defined.
If it was in functional Component then this it undefined
So if your trying to read input elements value use this,
<input onChange={e => console.log(e.target.value)} />
Read More,
Function And Class Components

Refresh the page after clicking on the area [duplicate]

This question already has answers here:
Button that refreshes the page on click
(18 answers)
Closed 3 years ago.
I want to refresh my website after clicking on a specific area (container)
Any ideas?
THANKS!
You can use Location.reload() API interface (https://developer.mozilla.org/ru/docs/Web/API/Location/reload)
So the answer could look as follows:
document.querySelector('you-area-selector-here').addEventListener((click) => {
window.location.reload(true);
})
true flag is required to be sure the page was reloaded from server, not from cache.
It is not a good practice to mix js with HTML.
I would do it this way:
let refreshPage = document.querySelector('#div1').addEventListener('click', => {
location.reload();
})
note: you must give id or class to the element you are trying to select in this function.
There are other way of doing it i.e = document.querySelectorAll, getElementById, getElementByClassName, getElementByTagName.

prevent negative numbers but accept decimals? HTML [duplicate]

This question already has answers here:
Is there a float input type in HTML5?
(14 answers)
Closed 4 years ago.
Is there's a way to prevent negative numbers but accept decimals? I'm using PHP and HTML
<input type="number" min="0" id="Student" name="course[]" value="<?php echo $_POST['course'][3]; ?>"/></p>
Your code theoretically works. It prevents negative numbers and accepts decimals.
I think what you're really asking is this: Is there a float input type in HTML5?
to which the top answer suggests that you would write:
<input type="number" min="0" step="0.01" name="course[]">
The thing that matters the most though is not client-side validation, but server-side validation. In the PHP code that accepts this input, you have to validate that the input is valid as follows:
if(is_numeric($_POST['course'][3]) && floatval($_POST['course'][3]) >= 0) {
// The rest of your code.
}
To do this for all the courses, you would most likely write:
foreach($_POST['course'] as $k => $v) {
if(!(is_numeric($v) && floatval($v) >= 0)) {
echo "Input needs to be a number.";
break;
}
// Process the course $_POST['course'][$k] here.
}
The main reason you have to check if it's a number in server-side too is that someone with certain knowledge about browsers can just open the browser console and edit the attributes of the input removing the type="number", allowing him to send you virtually any text.
Someone with even more knowledge can send you cURL requests.

Html text box that will redirect [duplicate]

This question already has an answer here:
Javascript URL Redirection based on a text box
(1 answer)
Closed 5 years ago.
m pretty terrible at web design and i just wanted to know how to make a text box that will redirect after putting in a certain phrase and pressing enter.
Thanks for help
This should work:
<form><input id="myInput" onblur="myFunction()" /></form>
<script>
function myFunction() {
if(document.getElementById('myInput').value == 'test') {
window.location.href='http://www.google.com';
}
}
</script>
See: https://codepen.io/anon/pen/gxLGgE

How do I check all checkboxes on an HTML page with one click? [duplicate]

This question already has answers here:
Closed 14 years ago.
I am html page with 5 checkboxes
My requirement is to have one morecheckboxes "Select All" which is used to select all 5 checkboxes.
Thanks in advance
Closed as exact duplicate of this question.
If you're looking for javascript that will check your 5 checkboxes when the 6th is clicked, something like this should work:
function CheckAll(value){
document.getElementByID("CheckBox1").checked = value;
document.getElementByID("CheckBox2").checked = value;
document.getElementByID("CheckBox3").checked = value;
document.getElementByID("CheckBox4").checked = value;
document.getElementByID("CheckBox5").checked = value;
}
<input type="checkbox" id="CheckBox6" onclick="CheckAll(this.checked)"><label>Check All</label>
In "pure" HTML, you can't, though you can modify your server-side code to correctly interpret that checkbox as meaning "act as though all the others were checked".
It's fairly easy using Javascript. Create a method that is fired when the "select all" checkbox is checked, and then find the other checkboxes by ID and mark them as checked. It's unclear what you should do if the "select all" checkbox is unchecked though, so perhaps it should just be a link.
You can't do this in just HTML, but should be fairly simple with javascript.
Personally I would use jQuery like this: http://abeautifulsite.net/notebook/50
This is a job for jQuery. Spend some time today and learn about it if you can. It's awesome for just this sort of task.