Hello!
Please, I have input value which I wanbted to “slice” to array index places and then turn the value on each index to a number, like…
<!DOCTYPE html>
<html>
<head>
<script>
function m(){
var a=document.getElementById("demo").value;
var array = a.split('');
var a2=array.length;
alert(a2);
alert(array[3]);
var c=document.getElementsByName("marc")[0].value;
alert(c);
var m1=parseInt('c',10);
alert(m1);
for (x=0;x<c;x=x+2){
if (a2[x]==c){alert("Letter is there!")}
else
{alert("This letter is not there.")}
}
}
</script>
</head>
<body>
<form>
<input type="text" id="demo" value=""/><br>
<p>Write a letter</>
<input type="text" name="marc" value=""/>
<input type="button" value="click" onclick="m()"/>
</form>
</body>
</html>
I amthe beginner with JS, will that be too complicatd _-
Manz thanks!!
I converted c to number value, but I cant convert a2 into number value :think…
<!DOCTYPE html>
<html>
<head>
<script>
function m(){
var a=document.getElementById("demo").value;
var array = a.split('');
var a2=array.length;
alert(a2);
alert(array[3]);
var c=document.getElementsByName("marc")[0].value;
alert(c);
var m1=parseInt(c,10);
alert(m1);
m2=m1+3;
alert(m2);
for (x=0;x<c;x=x+2){
if (parseInt(a2[x])==c){alert("Letter is there!")}
else
{alert("This letter is not there.")}
}
}
</script>
</head>
<body>
<form>
<input type="text" id="demo" value=""/><br>
<p>Write a letter</>
<input type="text" name="marc" value=""/>
<input type="button" value="click" onclick="m()"/>
</form>
</body>
</html>
I’m afraid I don’t quite understand what you are trying to do.
You have two inputs (demo and marc).
What input should they receive?
What output should be produced when one clicks on the button?
Please give us a concrete example.
Hello!
I shoul dactually input numbers but then I have to sumarise fist third, fifth…inother words, if I imagine numbers input as an numbers array then I shoudl get in output sum of all numbers which index is odd…
f.e.:
i imaput:
234567
and I have to get as output sum of 2+4+6
so I get in output: 12 in this case
You put your JavaScript at the bottom of the page, so that it is only evaluated after any of the elements it might reference (the input and the button in this case) are present on the page.
Now, as was pointed out in your other thread, you should use unobtrusive event handlers, i.e.