Похожие чаты

Hello guys I want to get a value from user using

object methods

For example:
const user = {
value: document.getElementById('input')
}

function showValue () {
alert(user.value);
}

I want to call the user input using user object and value property and alert the user input by clicking on the submit button

Can anyone help me with that?

10 ответов

20 просмотров

document .getElementById('submitButton') .addEventListener('click', showValue);

Thomas
document .getElementById('submitButton') .addE...

pass user to showValue() while you are at it

Iran- Автор вопроса
Thomas
document .getElementById('submitButton') .addE...

It doesn't work It still shows null to be clear, I'm using a button not a submit input and I have an onClick event inside my HTML document = my function and I think using an event inside my JS code is not a good idea

Iran
It doesn't work It still shows null to be clear, ...

Well then the element doesn't exist when you create the user object

Zeus
need to use document onready

Or move the script tag below the element

Iran- Автор вопроса
Thomas
Well then the element doesn't exist when you creat...

This is my HTML code <input type="text" id="input"> <button id="submit" onClick="showValue()">Click me</button> And this is my external JS code let user = { value: document.getElementById('input') } function showValue () { alert(user.value); } But I get null And I think the browser doesn't care about my input tag

Iran
This is my HTML code <input type="text" id="in...

Where is your external JS code <script> tag?

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта