<!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);
But this one not:
<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")[1].value;
alert(c);
var m1=parseInt(c,10);...
Could you provide more context (i.e. A code sample we can run to recreate your issue).
Also, if this has to do with your current problem, it is better to keep everything in one thread (this one) as opposed to starting new threads for every issue.
document.getElementsByName(“marc”)[0] would refer to the first input above and…
document.getElementsByName(“marc”)[1] would refer to the second input above.
If that’s not the problem then as Pullo said more information is required and indeed if this is part of your other thread then continue the conversation in that thread
Hello!
No, I have just one input with the name=“marc”, that is why I wondered at the very beginning why do I have to add [0], meaning, how it “knows” that it goes - or at least, can go,for an array.
If I had 2 inputs with the same name I would conclude it alone… but that way I find it a little bit confusing…at least for me at the moment( i meet ths stuff first time )
Because ''getElementsByName" returns a collection even if there is only one item on the page and to identify that item you use [0]. In your example you used [1] which means that there are two such elements and if there are not two elements then it won’t match anything.
Yes, I understand now, thank, but probelm is I ment second input box (the one with name =“marc”, and I can input in there on enumber or sign , or more of them,
I ment, If I put f.e. 34, index 0 would be for 3 and index 1 for 4…
otherwise, it works with only on ecipher number and does nto with more cipher numbers…
If the value entered for the input with name=“marc” was 34 then marc[0] = 34 (or whatever other number was entered). marc[1] doesn’t exist because you only have one input on the page with that name.
If the question is that you want to split the value you receive into separate digits then that is better answered by @James_Hibbard