Guys help please, I can not write a javi script, I need that when I select the "input" block in the select "sale", well, so that it disappears when others choose

Select Sale Exchange Gift

in the css block div id = "price" display: none;

Closed due to the fact that the issue is too general for participants user207618, user194374, Denis , aleksandr barakin , dirkgntly Aug 21 '16 at 8:09 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    There is a suspicion that in such cases a code sufficient for understanding the situation is given, and not just a lot of information being dumped onto the users :) - Sleepy Panda
  • I wrote it myself in 4 lines of javi, I had a block but it is not visible for some reason :( - Eugene
  • On the first select, an onchange event listener is hung onchange , which is called upon selection. Inside the function, we check the current value ( value ) of our select: if the item we need is selected, we show the second input. And yes, @SleepyPanda is right, in such matters it is supposed to attach the existing code. html + js. preferably in the form of a snippet, which can be immediately launched. - Ivan Pshenitsyn

1 answer 1

On the first select, an onchange event listener is hung onchange , which is called upon selection. Inside the function we check what is now selected: if the item we need is shown the second input.

Using jQuery, it looks like this:

a working example on jsfiddle (local snippets are spoiled): https://jsfiddle.net/ipshenicyn/0m8xbsy1/2/

HTML

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <select name="select" id="select"> <option value="1">Первый пункт</option> <option value="2">Второй пункт</option> <option value="3">Третий пункт</option> <option value="4">Четвертый пункт</option> </select> <input id="input" type="text" name="input" style="display:none"> 

Js

 $("#select").on('change', function(){ if($(this).val() == 3){ $("#input").show(); } else { $("#input").hide(); } }) 
  • Ivan, thank you very much, I understood my mistake, I didn’t indicate the numbers in value, but the text, as I changed everything to numbers, I apologize for forcing you to write everything, I didn’t read how to send scripts ( Eugene
  • @ Yevgeny nothing terrible, the main thing that figured it out. Generally speaking, there is no difference, the numbers in the value or the text. Error you had, apparently, in something else. Please mark the answer useful if it helped you. To do this, check the box to the left of the answer. - Ivan Pshenitsyn
  • Ivan, could you help me with validation? ru.stackoverflow.com/questions/557704 - Eugene