Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,142 members, 7,815,004 topics. Date: Thursday, 02 May 2024 at 04:25 AM

Whats An Easy Solution To This Javascript Issue - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Whats An Easy Solution To This Javascript Issue (329 Views)

Can Someone Help Me With With This Javascript Exercise Please / Help Me With This Javascript Problem / Javascript Issue (2) (3) (4)

(1) (Reply) (Go Down)

Whats An Easy Solution To This Javascript Issue by morzook(m): 8:51pm On Sep 06, 2022
I am trying to populate the boxes one after the other with the value of input field. If I add an input, all the boxes gets updated at once, which isn't what I need.

Re: Whats An Easy Solution To This Javascript Issue by thug: 9:52pm On Sep 06, 2022
You don't need the for loop function,
Also u didn't get the value of the input in the DOM.
Did u copy those code?? Cos I can see two for loops and they are doing the same thing.
Rewrite the code without the for loop then get the value of the input from the DOM.
Re: Whats An Easy Solution To This Javascript Issue by Nobody: 12:42am On Sep 07, 2022
Your code is doing exactly what you’re asking of it. It’s looping through all the childNodes of the target div and setting their html to be your input value.
You’re going about the logic the wrong way.
At each button click, loop through all the child divs inside the target element and once you find the first one with a null value, assign it the value of the input and return from the function at once to ensure that only one div is populated. Don’t forget to clear out the current value of the input before leaving the function.
Also use descriptive names for your functions and variables.
This code should work fine.

3 Likes

Re: Whats An Easy Solution To This Javascript Issue by RepoMan007: 4:56pm On Sep 07, 2022
Follow the advice of the poster above me. Enter the current input value into only the first null value div encountered and not all the divs. Are you building a data entry app.

(1) (Reply)

Web Design, SEO And Digital Marketing Company In Enugu / How Do I Recover My Facebook Account/ Whatsapp / Our Courses We Teach

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.