How can I display text based on the selected option or text entered in the input field?
The default text that appears is "Aa Bb Cc Dd Ee…", if I select another text in the options, it will change.
And if I type in the input field, it will also change based on what was input.
If I select the text again in the select option, the text will also change according to what I selected, and delete the text in the input field
<select id="font-sample-option">
<option value="1" selected="selected">Aa Bb Cc Dd Ee...</option>
<option value="2">The quick brown fox...</option>
<option value="3">When zombies arrive...</option>
</select>
<span>Or</span>
<input id="font-sample-input" placeholder="Type here ..." maxlength="55" type="text">
// Display selected text from the select option or input field
<span class="font-sample-display">Aa Bb Cc Dd Ee...</span>
3
Answers
As I got right you need something similar to:
//.html
//.js
You can listen for the change event on the select element and the input event on the text input element.
If the value of the select element is 4 (well, could be anything) the fieldset will be enabled and the user can write something in the text input. You can hide the text input by setting a CSS selector for
fieldset:disabled {display: none;}
. The nice thing about disabled elements in a form is that they are not included in the submit event.Just using javascript manipulate html element.