Click here to Skip to main content
15,501,490 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: One big collection or nested collections Pin
Pete O'Hanlon14-Sep-22 21:54
mvaPete O'Hanlon14-Sep-22 21:54 
GeneralRe: One big collection or nested collections Pin
waldette 202215-Sep-22 7:13
Memberwaldette 202215-Sep-22 7:13 
QuestionPinch zoom in zoom out in js Pin
madhuri jawadekar11-Sep-22 21:01
Membermadhuri jawadekar11-Sep-22 21:01 
Questionhow to make campaign windows Pin
Member 157551811-Sep-22 21:22
MemberMember 157551811-Sep-22 21:22 
AnswerRe: how to make campaign windows Pin
Richard MacCutchan1-Sep-22 23:02
mveRichard MacCutchan1-Sep-22 23:02 
AnswerRe: how to make campaign windows Pin
Dave Kreskowiak2-Sep-22 13:56
mveDave Kreskowiak2-Sep-22 13:56 
QuestionIs there a way to input a unique number for each array output? Pin
machinewraith31-Aug-22 16:46
Membermachinewraith31-Aug-22 16:46 
AnswerRe: Is there a way to input a unique number for each array output? Pin
Richard Deeming1-Sep-22 23:23
mveRichard Deeming1-Sep-22 23:23 
You already have a number, which you're using as the index in the for loop. You just need to add 1 to get the numbers to start at 1 instead of 0.

You'll also want to HTML-encode the user-supplied data so that it displays properly. The simplest way to do that is to create an element and set its innerText property.
JavaScript
const favoriteCities = function() {
    const output = document.getElementById("output");
    output.innerHTML = "";
    
    const input = document.getElementsByName("favoriteCities[]");
    for (let i = 0; i < input.length; i++) {
        const div = document.createElement("div");
        div.innerText = `City #${i + 1} is ${input[i].value}`;
        output.appendChild(div);
    }
};




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

Questionjavascript looping pattern question Pin
ravindra Yadav 202213-Aug-22 2:22
Memberravindra Yadav 202213-Aug-22 2:22 
AnswerRe: javascript looping pattern question Pin
Richard MacCutchan13-Aug-22 2:31
mveRichard MacCutchan13-Aug-22 2:31 
QuestionJavascript Pin
User 1567076229-Jul-22 1:20
MemberUser 1567076229-Jul-22 1:20 
AnswerRe: Javascript Fibonacci sequence Pin
Richard MacCutchan29-Jul-22 4:28
mveRichard MacCutchan29-Jul-22 4:28 
RantRe: Javascript Pin
Richard Deeming1-Aug-22 1:29
mveRichard Deeming1-Aug-22 1:29 
QuestionI need help in defining and calling Static variable in Typescript. Pin
Afi_sh26-Jul-22 6:01
MemberAfi_sh26-Jul-22 6:01 
AnswerRe: I need help in defining and calling Static variable in Typescript. Pin
Jeremy Falcon26-Oct-22 12:41
professionalJeremy Falcon26-Oct-22 12:41 
QuestionNew to Coding Pin
John Wiser25-Jul-22 4:05
MemberJohn Wiser25-Jul-22 4:05 
AnswerRe: New to Coding Pin
Richard MacCutchan25-Jul-22 4:10
mveRichard MacCutchan25-Jul-22 4:10 
GeneralRe: New to Coding Pin
John Wiser25-Jul-22 10:44
MemberJohn Wiser25-Jul-22 10:44 
AnswerRe: New to Coding Pin
Jeremy Falcon26-Oct-22 12:49
professionalJeremy Falcon26-Oct-22 12:49 
QuestionI need help with a task Pin
User 1567076221-Jul-22 12:35
MemberUser 1567076221-Jul-22 12:35 
AnswerRe: I need help with a task Pin
jeron121-Jul-22 12:56
Memberjeron121-Jul-22 12:56 
GeneralRe: I need help with a task Pin
jsc4225-Jul-22 5:11
professionaljsc4225-Jul-22 5:11 
QuestionI need help with an Javascript exercise! Pin
User 1567076215-Jul-22 21:39
MemberUser 1567076215-Jul-22 21:39 
GeneralRe: I need help with an Javascript exercise! Pin
Richard MacCutchan15-Jul-22 22:29
mveRichard MacCutchan15-Jul-22 22:29 
GeneralRe: I need help with an Javascript exercise! Pin
User 1567076215-Jul-22 23:59
MemberUser 1567076215-Jul-22 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.