Skip to content
Advertisement

Using JS variable as the property of HTML input Form

I have a form which have two field “optin” and “Qty”.The quantity field of the form accept the number.The minimum number which can be entered in this field(QTY) depends upon the the value of the Option field i.e. If the option fiels value is red then the minimum value propert of the Qty field should be 5 and if it is ‘Red’ then the minimum property of the Qty field should be 10. I am doing it by the given code but its not working.

JavaScript

Advertisement

Answer

JavaScript

Let’s see… First of all lets change your if else case with a switch:

JavaScript

Now I will remove the php tag and add a line to change the min value of the input.

JavaScript

Now let’s see this code in action! Run the following snippet.

JavaScript

And done! Also, I changed the onkeydown to onchange.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement