There is a text field, it is allowed to enter only numbers.

<script type="text/javascript"> window.onload = function(){ document.getElementById('input').onkeyup = function(){ this.value = this.value.replace(/[^\d]/g,''); }; }; </script> <input type="text" id="input" /> 

Required: after entering the number below, the image should appear by clicking on which the select field will appear with the choices for the specified number. Example: number 1 is entered, an image appears below, clicked, the select field opened with options: text1, text2 ... For figure 2, similarly, except for the options. How to implement?

  • And what have you tried to do? What exactly did not work out? - Dmitriy Simushev
  • I do not know how to display the image below after entering the number - Alex Demonov
  • one
    show how you tried. and where to output - Saidolim
  • one
    Have you ever tried to do it yourself? - HELO WORD
  • Unfortunately, I don’t know js, but I need to do it today, so I’m asking for help ... There is a text field, enter a number and, depending on the number, display the corresponding image below the text field. - Alex Demonov

1 answer 1

The approach to solving the problem should be as follows:

A handler is added to the change event of the input field. This handler creates an HtmlElement for the image, and the src attribute of this element is set depending on the value of the input field. The resulting element is inserted into the DOM document tree at the right place.

I will not write the code in principle, because the author asks to explain the principle in the commentary. You can minus =)