javascript - Pure JS - display:block not working -



javascript - Pure JS - display:block not working -

i know has been asked 1000000 times swear, checked 20 posts , nil works...

this code:

when utilize clicks on "email" option, input element id of "email" should show underneath it.

html

<select> <option selected disabled>contact me by:</option> <option onclick="showinput()">email</option> </select> <input class="email" id="email" placeholder="email address" type="text" />

js

class="lang-js prettyprint-override">function showinput() { document.getelementbyid("email").style.display = "block"; }

css

class="lang-css prettyprint-override">input#email { display: none; }

could explain me how not working? have link js file before body closing tag.

use onchange event , move event handler <select> element. added value attribute <option> element create text field identification simpler. and, finally, in function, pass select element event handler , grab selected alternative select list.

<select onchange="showinput(this)"> <option selected disabled>contact me by:</option> <option value="email">email</option> </select> <input class="email" id="email" placeholder="email address" type="text" /> <script> function showinput(sel) { var opt = sel.options[sel.selectedindex].value document.getelementbyid(opt).style.display = "block" } </script>

jsfiddle

now can add together more contact options:

<select onchange="showinput(this)"> <option selected disabled>contact me by:</option> <option value="email">email</option> <option value="phone">phone</option> <option value="address">mail</option> </select> <input class="email" id="email" placeholder="email address" type="text" /> <input class="phone" id="phone" placeholder="phone number" type="text" /> <input class="address" id="address" placeholder="mailing address" type="text" />

javascript html css block

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -