BR
asked on
getting the first 6 numbers from an input with javascript
Dear experts,
when user leave the input area, I want to get the first 6 numbers of the input and put it into str variable.
How can I do that? thank you
<input type="tel" name="number" id="number" required>
when user leave the input area, I want to get the first 6 numbers of the input and put it into str variable.
How can I do that? thank you
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
document.getElementById("seh").innerHTML = str;
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are most welcome.
use :
var six = yourstring.substr(0,6);
var six = yourstring.substr(0,6);
<input type="tel" name="number" id="number" required onblur="showUser(this.value.substr(0,6))">
ASKER
you are answer is perfect. thank you so much