hello my first time problem click button idk

here i send look
58 Replies
IAM
IAM3mo ago
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<button type="button" id="b1"></button><button type="button" id="b2"></button><button type="button" id="b3"></button><button type="button" id="b4"></button><button type="button" id="b5"></button><button type="button" id="b6"></button><button type="button" id="b7"></button><button type="button" id="b8"></button>
#long
<input type="text" id="middle-input">
</body>
</html>
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<button type="button" id="b1"></button><button type="button" id="b2"></button><button type="button" id="b3"></button><button type="button" id="b4"></button><button type="button" id="b5"></button><button type="button" id="b6"></button><button type="button" id="b7"></button><button type="button" id="b8"></button>
#long
<input type="text" id="middle-input">
</body>
</html>
but i use this like <input type="text" id="middle-input">
IAM
IAM3mo ago
there js
IAM
IAM3mo ago
window.onload = function() {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.onclick = function() {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerText;
}
}
};
window.onload = function() {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.onclick = function() {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerText;
}
}
};
it's not working...
mustafaelrasheid
?????
IAM
IAM3mo ago
huh?
mustafaelrasheid
sorry
IAM
IAM3mo ago
what? it's ok but can help me?
mustafaelrasheid
got confused with 200lines of code
IAM
IAM3mo ago
i cant click
No description
IAM
IAM3mo ago
i know this long
IAM
IAM3mo ago
No description
IAM
IAM3mo ago
No description
Jochem
Jochem3mo ago
This is why it's best to share your code in something like codepen, so that people can run it easily for themselves
IAM
IAM3mo ago
hm? sec
Jochem
Jochem3mo ago
it's explained in #How To Ask Good Questions
IAM
IAM3mo ago
like this
No description
IAM
IAM3mo ago
this like problem wasnt show text ?
mustafaelrasheid
what about generating the buttons in code and then displaying them? cleaner
IAM
IAM3mo ago
yes console.log i want like this there text
IAM
IAM3mo ago
No description
IAM
IAM3mo ago
but like click
IAM
IAM3mo ago
No description
mustafaelrasheid
try using () => {} instead of function() {}
IAM
IAM3mo ago
huh? where?
mustafaelrasheid
try using innerHTML instead of inner text
IAM
IAM3mo ago
ya mustafa asma trane arbe xd bs sadle
mustafaelrasheid
window.onload = function() {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.onclick = () => {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerHTML;
};
}
};
window.onload = function() {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.onclick = () => {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerHTML;
};
}
};
IAM
IAM3mo ago
nope?
No description
IAM
IAM3mo ago
No description
mustafaelrasheid
document.addEventListener('DOMContentLoaded', () => {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.click = () => {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerHTML;
};
}
});
document.addEventListener('DOMContentLoaded', () => {
for (let i = 1; i <= 64; i++) {
let button = document.getElementById('b' + i);
button.click = () => {
console.log(button.innerText);
document.getElementById('middle-input').value = button.innerHTML;
};
}
});
did it work?
IAM
IAM3mo ago
No description
IAM
IAM3mo ago
but console works but text not working
mustafaelrasheid
we are getting there...
IAM
IAM3mo ago
hm?
IAM
IAM3mo ago
i can send but there
IAM
IAM3mo ago
im waiting lol
mustafaelrasheid
your spaghetti code seems tuff to fix give me sometime
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<div id="button-container">
</div>
</body>
</html>
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<div id="button-container">
</div>
</body>
</html>
IAM
IAM3mo ago
huh? what you mean? <div id="button-container"> ?? @mustafaelrasheid uh
mustafaelrasheid
document.addEventListener(
'DOMContentLoaded',
() => {
for (let i = 1; i <= 64; i++) {
let button = document.createElement("button");
let array = ["h","b","",...];
let item = array[i];
button.onclick = () => {
console.log(item);
};
document.getElementById("button-container").appendChild(button);
}
}
);
document.addEventListener(
'DOMContentLoaded',
() => {
for (let i = 1; i <= 64; i++) {
let button = document.createElement("button");
let array = ["h","b","",...];
let item = array[i];
button.onclick = () => {
console.log(item);
};
document.getElementById("button-container").appendChild(button);
}
}
);
what do you see? did it work?
IAM
IAM3mo ago
No description
IAM
IAM3mo ago
? @mustafaelrasheid
mustafaelrasheid
see, it works with less bloat what is your home language by the way? your native tough?
IAM
IAM3mo ago
wha? wait huh? can send me ? wdym?
IAM
IAM3mo ago
oh? so can send me ?
mustafaelrasheid
html file:
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<div id="button-container">
</div>
<input id="middle-input"/>
</body>
</html>
<html>
<head>
<link rel="stylesheet" href="css/2001_mars_odyssey.css" id="normal">
<link rel="stylesheet" href="hi.css">
</head>
<body>
<div id="button-container">
</div>
<input id="middle-input"/>
</body>
</html>
js file"
document.addEventListener(
'DOMContentLoaded',
() => {
for (let i = 1; i <= 64; i++) {
let button = document.createElement("button");
let array = "your text";
button.something = array[i];
button.onclick = (event) => {
console.log(event.target.something);
document.getElementById("middle-input").value = event.target.something;
};

document.getElementById("button-container").appendChild(button);
}
}
);
document.addEventListener(
'DOMContentLoaded',
() => {
for (let i = 1; i <= 64; i++) {
let button = document.createElement("button");
let array = "your text";
button.something = array[i];
button.onclick = (event) => {
console.log(event.target.something);
document.getElementById("middle-input").value = event.target.something;
};

document.getElementById("button-container").appendChild(button);
}
}
);
IAM
IAM3mo ago
that's weird but you didnt use?
IAM
IAM3mo ago
IAM
IAM3mo ago
this? wait let me send you ? can send me this link?
mustafaelrasheid
because it is too much code for the client to load
IAM
IAM3mo ago
hm? im waiting
Jochem
Jochem3mo ago
everyone here volunteers their time. That means that it may take minutes or hours or days before you get a reply, or you may not even get one. That is simply how this server works. Please be more patient, especially when people are already helping you.
IAM
IAM3mo ago
ok. but problem sadly
Jochem
Jochem3mo ago
I don't understand what that means
IAM
IAM3mo ago
oh wait it's works @mustafaelrasheid
IAM
IAM3mo ago
but like this
No description
IAM
IAM3mo ago
almost Thank you @mustafaelrasheid