Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Development
HTML and CSS
Reversing output of user input by using while loop...
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="machinegod, post: 5171232, member: 92202"] I'm new to programming and I've read and watched several resources about for, while loops, but everytime I write the while loop to reverse the output from the for loop, the code doesn't run properly. I'm sort of just guessing at this point. Does anyone know of a good article/video to better understand reversing the output from user input by using a while loop? I commented out the while loop I was working on. [CODE=html]<html> <body style="text-align:center;"> <h1>Enter Your Five Favorite Cities</h1> <form class="" action="index.html"> <input type="text" name="favoriteCities[]" value="" /><br> <br> <input type="text" name="favoriteCities[]" value="" /><br> <br> <input type="text" name="favoriteCities[]" value="" /><br> <br> <input type="text" name="favoriteCities[]" value="" /><br> <br> <input type="text" name="favoriteCities[]" value="" /><br> <br> <button type="button" name="button" onclick="favoriteCities()">Submit</button> </form> <h2>Results</h2> <p id="output"></p> <script type="text/javascript"> var r = ""; function favoriteCities() { var input = document.getElementsByName('favoriteCities[]'); for (var i = 0; i < input.length; i++) { var a = input[i]; var uniqueNumber=i+1; r = r + "City #" + uniqueNumber + " is " + a.value + ("<br>"); } document.getElementById("output").innerHTML = r; //while (4 = input.length) { //print (output) //} } </script> </body> </html>[/CODE] [/QUOTE]
Verification
Post reply
Forums
Development
HTML and CSS
Reversing output of user input by using while loop...
Top