JS/JQuery: select value of OR from text input


Eagle

I want my user to select a value from the <select>component , but if he can't find the correct value in it, <select>I want him to be able to enter a value himself.

I know how to do it the dirty way: if he clicks the checkbox, I deactivate <select>and activate the text input on the side of the selection. Using angular JS, I can even make the selection disappear and be replaced by the text input.

However, is there a single component that would allow me to fix this without adding checkboxes to tick (limited space on this page and I'd like to save some)?

wawa

My option is not in the listYou can add an option (such as a value) 0(or a value you prefer ) to the select dropdown and attach a change event to the selection. When the value of select changes to 0, you can use jQuerys function replceWithto replace the select with a text input field : http://api.jquery.com/replacewith/

EDIT: I did a little fiddle, this should be easier to understand than the above ;) http://jsfiddle.net/azumon0L/
NOTE: You can use any name in the text input, I'm just assuming here, that you want to match the selection ...same

Edit2: Unspecified user should be able to go back to select, and didn't add it since I'm a lazy jerk. However, I've updated the solution and now it does what you want! http://jsfiddle.net/azumon0L/2/

Related


JS/JQuery: select value of OR from text input

Eagle I want my user to select a value from the <select>component , but if he can't find the correct value in it, <select>I want him to be able to enter a value himself. I know how to do it the dirty way: if he clicks the checkbox, I deactivate <select>and act

Puppeteer - select value from <select> input element

Novice development What's the best way to select an option from a select input type in a puppeteer form? I've heard that there is a bug in puppeteer and that .type()method is not the ideal way to proceed. A select input type in a form has option values set in

Match input text to option value and automatically select it

Mina Hafzalla I have an input field and a select label like this: <input type="text" id="domain"/> <select> <option value=".com">.com</option> <option value=".net">.net</option> <option value=".org">.org</option> </select> <input type="sub

jQuery select next text input value

username I have dynamic checkboxes along with corresponding text inputs. When the checkbox is checked for a specific checkbox, the value of the text input is alerted what I want to achieve. I can't seem to get the value of the text input. Currently, all checkb

Change SELECT value based on input text

Lucas Bustamante <input type="text" id="registersld" /> <select id="registertld"> {foreach key=num item=listtld from=$registertlds} <option value="{$listtld}"{if $listtld eq $tld} selected="selected"{/if}>{$listtld}</option> {/foreach} </select> This is a dom

Match input text to option value and automatically select it

Mina Hafzalla I have an input field and a select label like this: <input type="text" id="domain"/> <select> <option value=".com">.com</option> <option value=".net">.net</option> <option value=".org">.org</option> </select> <input type="sub

jQuery select next text input value

username I have dynamic checkboxes along with corresponding text inputs. When the checkbox is checked for a specific checkbox, the value of the text input is alerted what I want to achieve. I can't seem to get the value of the text input. Currently, all checkb

Change SELECT value based on input text

Lucas Bustamante <input type="text" id="registersld" /> <select id="registertld"> {foreach key=num item=listtld from=$registertlds} <option value="{$listtld}"{if $listtld eq $tld} selected="selected"{/if}>{$listtld}</option> {/foreach} </select> This is a dom

Access select text value from Formik Select

Tony Fu I use the following code from the tutorial as a reusable component for Material-UI selection: import React from 'react'; import { TextField, MenuItem } from '@material-ui/core'; import { useField, useFormikContext } from 'formik'; const SelectWrapper

Pass value from button value to input text

Muhammad Aladdin Can I ask Angular I'm a beginner and I need to pass the value of Button to Input text I have many Buttons like When I press the button, the text value changes xx code xx If you are using angular js then the following can help you. var app = an

Update select input text from modal dropdown?

User 11509999 I have an example modal with two components dropdown and input text <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Test Modal</button> <div class

Get text from select option and send it to input

Phil Want to hone my JavaScript. I want the text from the select option dropdown to be sent to the input. I've found a way to do it. <select id="gren" onChange="return func1(this)"><option>1</option><option>2</option> <option>3</option><option>4</option></sele

Get text from select option and send it to input

Phil Want to hone my JavaScript. I want the text from the select option dropdown to be sent to the input. I've found a way to do it. <select id="gren" onChange="return func1(this)"><option>1</option><option>2</option> <option>3</option><option>4</option></sele

Dynamically select and populate input value from JQuery

Ying I have a jQuery code like this: let $options = JSON.parse(data.options); let $keys = Object.keys($options); $keys.forEach(function (item,index, array) { $('#' + item ).val($options[item] ); }); I want to populate all input values of id in $keys with da

Select input by value from list using JQuery

Chris Nevill I have a list that looks like this: <ul id='mylist'> <li> <input val="1"> </li> <li> <input val="2"> </li> </ul> How to select input by value using JQuery? I can get lee's list by $("#mylist").children('li') But c

Dynamically select and populate input value from JQuery

Ying I have a jQuery code like this: let $options = JSON.parse(data.options); let $keys = Object.keys($options); $keys.forEach(function (item,index, array) { $('#' + item ).val($options[item] ); }); I want to populate all input values of id in $keys with da

Display value of array from select input in Vuetify

Felipe Teixeira I have a set of data with city names and values attributed to the city. When someone selects a city, it should show that value. I know I can get by by choice {{selected.value}}. However, since I want to extract the value so that I can use it la

populate select input field with value from mysql

techAddict82 My form has input fields with values populated from a mysql table. In my select statement, I pass these values to the fields. The table is called personand has a unique ID person_idand foreign key academy_id. Each has a state activeor inactiveis s

populate select input field with value from mysql

techAddict82 My form has input fields with values populated from a mysql table. In my select statement, I pass these values to the fields. The table is called personand has a unique ID person_idand foreign key academy_id. Each has a state activeor inactiveis s

Append input value from select JQuery?

Schneider I have selected country code <select name="countryCode" id=""> <option data-countryCode="GB" value="44" Selected>UK (+44)</option> <option data-countryCode="US" value="1">USA (+1)</option> <optgroup label="Other countries"> <optio

Unable to get value from Input Type="select"

Batman I'm trying to get the value from the dropdown but can't do it. My dropdrop code is: <Input type="select" name="type" id="etype" value={this.state.type} onChange={this.changeTypeHandler}> <option value="Doctor">Doctor</optio

Load value from database to html select input

cresol I am saving this field in a MYSQL database. <select id="sel1" name="grpID"> <option value="">select</option> <option value="G00">option1</option> <option value="G01">option2</option> <option value="G02">option3</option> <option value="G03">opt

Select input by value from list using JQuery

Chris Nevill I have a list that looks like this: <ul id='mylist'> <li> <input val="1"> </li> <li> <input val="2"> </li> </ul> How to select input by value using JQuery? I can get lee's list by $("#mylist").children('li') But c

Dynamically select and populate input value from JQuery

Ying I have a jQuery code like this: let $options = JSON.parse(data.options); let $keys = Object.keys($options); $keys.forEach(function (item,index, array) { $('#' + item ).val($options[item] ); }); I want to populate all input values of id in $keys with da

Display value of array from select input in Vuetify

Felipe Teixeira I have a set of data with city names and values attributed to the city. When someone selects a city, it should show that value. I know I can get by by choice {{selected.value}}. However, since I want to extract the value so that I can use it la