+ 31

How can receive a number from user and use it in html tag ?

for example for this html code input x(number) from user and use that in <marquee scrollamount="x"> <marquee> https://code.sololearn.com/WTDuxdOWF90F/?ref=app

2nd May 2018, 7:20 AM
AliR૯za
AliR૯za - avatar
9 odpowiedzi
+ 5
<head> <script> function ScrollAmount () { var marquee = document.getElementById ("myMarquee"); var input = document.getElementById ("amount"); marquee.scrollAmount = input.value; } </script> </head> <body> <marquee id="myMarquee" style="width:150px;" scrollamount="10">Hi There!</marquee> <br /> <input id="amount" type="text" value="20" /> <button onclick="ScrollAmount ();">Change scrollAmount!</button> </body>
2nd May 2018, 7:53 AM
Sudarshan Rai
Sudarshan Rai - avatar
2nd May 2018, 8:34 AM
AliR૯za
AliR૯za - avatar
+ 27
Shudarshan Rai Yes 😁 but why it just change first marquee tag ? is it possible to change all of scrollamount with using one input?
2nd May 2018, 8:10 AM
AliR૯za
AliR૯za - avatar
+ 25
Shudarshan Rai Thanks alot
2nd May 2018, 7:59 AM
AliR૯za
AliR૯za - avatar
+ 12
Updated: applies to all elements AliR૯za 1st Prompt for a user input 2nd select all elements with querySelectorAll 3rd loop through the nodelist with foreach then apply setAttribute to all elements //Javascript code this.addEventListener("DOMContentLoaded", boot) function boot(){ var inpt = prompt("enter a no"), mar = document.querySelectorAll("marquee") mar.forEach(function(node){ node.setAttribute("scrollamount", inpt) }); }
2nd May 2018, 8:01 AM
Lord Krishna
Lord Krishna - avatar
2nd May 2018, 7:57 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
AliR૯za 👍👍 Is this helped you 😁
2nd May 2018, 7:59 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
AliR૯za you can by giving them different id
2nd May 2018, 8:30 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
wow that's awesome 😍
5th May 2018, 7:15 AM
Explore Further
Explore Further - avatar