hello my first time problem click button idk

here i send look
58 Replies
IAM
IAMOP7mo 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
IAMOP7mo ago
there js
IAM
IAMOP7mo 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
IAMOP7mo ago
huh?
mustafaelrasheid
sorry
IAM
IAMOP7mo ago
what? it's ok but can help me?
mustafaelrasheid
got confused with 200lines of code
IAM
IAMOP7mo ago
i cant click
No description
IAM
IAMOP7mo ago
i know this long
IAM
IAMOP7mo ago
No description
IAM
IAMOP7mo ago
No description
Jochem
Jochem7mo 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
IAMOP7mo ago
hm? sec
Jochem
Jochem7mo ago
it's explained in #How To Ask Good Questions
IAM
IAMOP7mo ago
like this
No description
IAM
IAMOP7mo ago
this like problem wasnt show text ?
mustafaelrasheid
what about generating the buttons in code and then displaying them? cleaner
IAM
IAMOP7mo ago
yes console.log i want like this there text
IAM
IAMOP7mo ago
No description
IAM
IAMOP7mo ago
but like click
IAM
IAMOP7mo ago
No description
mustafaelrasheid
try using () => {} instead of function() {}
IAM
IAMOP7mo ago
huh? where?
mustafaelrasheid
try using innerHTML instead of inner text
IAM
IAMOP7mo 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
IAMOP7mo ago
nope?
No description
IAM
IAMOP7mo 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
IAMOP7mo ago
No description
IAM
IAMOP7mo ago
but console works but text not working
mustafaelrasheid
we are getting there...
IAM
IAMOP7mo ago
hm?
IAM
IAMOP7mo ago
i can send but there
IAM
IAMOP7mo 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
IAMOP7mo 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
IAMOP7mo ago
No description
IAM
IAMOP7mo ago
? @mustafaelrasheid
mustafaelrasheid
see, it works with less bloat what is your home language by the way? your native tough?
IAM
IAMOP7mo ago
wha? wait huh? can send me ? wdym?
IAM
IAMOP7mo 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
IAMOP7mo ago
that's weird but you didnt use?
IAM
IAMOP7mo ago
IAM
IAMOP7mo 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
IAMOP7mo ago
hm? im waiting
Jochem
Jochem7mo 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
IAMOP7mo ago
ok. but problem sadly
Jochem
Jochem7mo ago
I don't understand what that means
IAM
IAMOP7mo ago
oh wait it's works @mustafaelrasheid
IAM
IAMOP7mo ago
but like this
No description
IAM
IAMOP7mo ago
almost Thank you @mustafaelrasheid
Want results from more Discord servers?
Add your server