What is wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is wrong?

function dpad(){ var a = document.createElement("input"); a.type = "number"; document.getElementsByTagName("body")[0].appendChild(a); a.click(); } window.onload = dpad; EDIT: EVERYTHING WORKS BUT I NEED TO FORCE A CLICK TO THE INPUT

15th Aug 2020, 3:54 AM
Zackery Spry
17 Answers
+ 2
Check this: https://www.w3schools.com/jsref/met_html_click.asp you need either: a.setAttribute("onclick", "action()"); // set the attribute or a.addEventListener("click", action); // create an event listener before simulating a click. perhaps what u want to do is focus(); a.focus(); // It'll go to the input box ready for u to type the number try focus instead of a.click(); and check the result. I'm a newbie too, so pardon me if I can't explain correctly.
15th Aug 2020, 5:38 AM
Arturop
Arturop - avatar
+ 2
It shows a number input as I run the code. Actually, I don't get what you mean by "make a number dpad"; are you talking about dial pad? like phone number? in that case, I guess you need an input with "tel" as 'type' attribute.
15th Aug 2020, 5:55 AM
Ipang
+ 1
https://code.sololearn.com/WBDpsgBkRODA/?ref=app The pad pops up when u use tablet smartphone, in PC no need cuz u have the keyboard.
15th Aug 2020, 6:25 AM
Arturop
Arturop - avatar
+ 1
Not sure what your intention is here, but dpad is a function and needs to be called as such. At the moment, you are simply assigning it to window.onload, but its not being invoked.
16th Aug 2020, 11:58 PM
Aaron Gillies
Aaron Gillies - avatar
0
What is the problem? What were you expecting from that code, provide more info please ...
15th Aug 2020, 5:30 AM
Ipang
0
U want a number pad like a calculator?
15th Aug 2020, 6:01 AM
Arturop
Arturop - avatar
0
Jorat Nope.
15th Aug 2020, 6:26 AM
Zackery Spry
0
I give up i tried my best hahahaha
15th Aug 2020, 6:27 AM
Arturop
Arturop - avatar
0
I tried to search how to force keyboard popup on mobile, but couldn't find a viable solution, unfortunately.
15th Aug 2020, 10:56 AM
Ipang
0
Answer: [0].appendChild(a); Wrong
16th Aug 2020, 7:18 AM
Bekzat Zhaksylykov
Bekzat Zhaksylykov - avatar
- 1
Ipang it does nothing. It is suppost to make a number dpad.
15th Aug 2020, 5:33 AM
Zackery Spry
- 1
Jorat it still does not work.
15th Aug 2020, 5:44 AM
Zackery Spry
- 1
I guess my device just doesn't support it.
15th Aug 2020, 5:56 AM
Zackery Spry
- 1
I want the number pad from type=number, but i can not get it to automatically pop up.
15th Aug 2020, 6:07 AM
Zackery Spry
- 1
Abdurrahim That has nothing to do with it
16th Aug 2020, 7:01 AM
Zackery Spry
- 1
PROGRAMMA No that part works i need to force the dpad to pop up.
16th Aug 2020, 7:19 AM
Zackery Spry
- 1
Aaron Gillies i need to use the function name because if i use the () identifier it thinks i want it to run what dpad returns and therefor runs the code before the window loads. Sorry for the realllly late reply
8th Nov 2020, 2:46 AM
Zackery Spry