JS- While loop and substring not entered correctly

Hi Guys, trying to get this JS to print the entered value down the page. Any pointers would be great.

function start(){
    var vName= document.getElementById("custname").value;
    document.getElementById("output1").innerHTML = "Name Entered: "+vName;
    document.getElementById("output2").innerHTML = processString(vName);
}

function processString(pString){
    var vIndex=pString.substring(10);
    var vReturnValue="Character List"+"<br>";

    while (vIndex < pString.length){
        vReturnValue= vReturnValue+pString.substring(0,1)+"<br>";
alert(vIndex);    
        vIndex++;
    }
    return vReturnValue;
}
By @uandurwords on Wed 26 Apr 2017 |
Tags javascript

Responses:

Offer your help. Be nice!

@eden
0

I'm not really sure what you're trying to do... Do you want to append the value of #custname to the page?

I'm simply trying to get a while loop to assign the value entered down the page separated by a <br>. e.g. James ( is entered into the span) page output is: j a m e s

@eden
0

There's a lot more going on here than there needs to be, I think. All you need is a for loop: codepen.io/anon/pen/OmWwXp

thanks eden.

Login to leave a response!