i am kind of new to it all but i have an input field where the user would input a string and i need it to come out split in the right final field depending on numerical and nonnumerical part of the string and no matter what i do it at runtime it only goes through the first IF statement regardless of the length which is my IF statement criteria
<pre>
<p>Click the button to extract characters from the string.</p>
<p id="demo1"></p>
<form>
<input id="userInput"><br>
<label> Non Numeric</label><textarea id="nonNumeric"> </textarea>
<label> Numeric</label><textarea id="numeric"> </textarea> <br>
<label> Numeric Result</label><textarea id="numericResult"> </textarea>
</form>
<button onclick="seventeenDigitChasSearch()">Try it</button>
</pre>
<script>
function seventeenDigitChasSearch() {
var str = document.getElementById("userInput").value ;
var nonNumeric = str.substring(0, 14); //checks between index 0 and 13
var numeric = str.substring(14, 17); ////checks between index 14 and 17
document.getElementById("nonNumeric").innerHTML = nonNumeric;
document.getElementById("numeric").innerHTML = numeric;
//convert the numeric number to an int value before evaluating it
intNumeric =parseInt(numeric) ;
if (intNumeric.toString().length = 17) {
nonNumeric = str.substring(0, 14);
numeric = str.substring(14, 17);
document.getElementById("nonNumeric").innerHTML = nonNumeric;
document.getElementById("numeric").innerHTML = numeric;
document.getElementById("numericResult").innerHTML = "Yaay value is within our of preferred";
}
else if (intNumeric.toString().length = 10) {
numeric = str.substring(0, 10);
document.getElementById("nonNumeric").innerHTML = "none";
document.getElementById("numeric").innerHTML = numeric;
document.getElementById("numericResult").innerHTML = "10 Range";
}
else if (intNumeric == null)
{
document.getElementById("numericResult").innerHTML = "Faulty out of ranged numbers";
}
} ```
Aucun commentaire:
Enregistrer un commentaire