javascript - Change placeholder text based on the dropdown selection? -
I have a selection box with some options that the user chooses, when the user selects "first name" Then I want to place your first name in the placeholder text to be displayed next to the text box. Please find your piece of code below:
HTML:
& Lt; Id = "selection type" & gt; & Lt; Option value = "- 1" & gt; Choose one & lt; / Options & gt; & Lt; Option value = "0" & gt; First name & lt; / Options & gt; & Lt; Option value = "1" & gt; Last name & lt; / Option & gt;
js:
var placeholder text = {"first name": "enter your first name", "last Name ":" Enter your last name "}; ("Change", function () {var selection = document.getElementById ("selectionType"); var input box = document.getElementById ("input box"); var selectedVal = $ ('# selectType') .find (': Selected '). Text (); if (placeholder text [selectedVal]! == undefined) {inputBox.placeholder = placeholderText [selectedVal];}});
It works fine in Chrome and FF, but it works in IE 8 & amp; 9 ... any help on this
View the demo:
Use it IE 8 & amp; Support in 9
Because IE 8 and 9 html5 do not support placeholders and only support in IE 10.
Ref:
Comments
Post a Comment