How to send value from select to input text in html using javascript?


Florian Chuculescu

I'm trying to send a value to based on the selection in a dropdown list. I want to get the value of possiblePhone.id and send it to .

<script>
function copyTextValue() {
    var text1 = document.getElementById("source").value;
    document.getElementById("destination").value = text1;

}
</script>


<div>
<select th:field="${possiblePhones}">
    <option value="0">select phone</option>
    <option id="source" onselect="copyTextValue()"
            th:each="possiblePhone : ${possiblePhones}"
            th:value="${possiblePhone.id}"
            th:text="${possiblePhone.model}"></option>
</select>
</div>

<td><input type="text" id="destination"> </td>

For example, if "Samsung" is selected, "1" should be sent to the input field, and so on. Actually, I don't get any output.

Nebster
<select id="source" onchange="copyTextValue()">
    <option value="0">select phone</option>
    <option value="1">samsung</option>
    <option value="2">something</option>
</select>

The id="source"attribute should be in the <select>element, it should also be changed onselectto onchangeand moved into the <select>element.

Codepen : https://codepen.io/anon/pen/WVxLpz

Related


How to get value or text from HTML select tag using JavaScript?

Christos In my html file I have the following: <td id="trainers_rowC1">Trainer1</td> <td><input type="button" id="edit_button1" value="Edit" class="edit" onclick="edit_rowC('1')"></td> In my javascript file I have this function: function edit_rowC(no) {

How to send characters to text input using Javascript

Mr. SirCode In my project: CSSHTML Keyboard, I have installed a keyboard based on an old laptop keyboard, a small project I did as a school homework. The problem is, I'm not sure how to add a specific character to the keyboard, eg: say I click Shift , then A/a

How to send characters to text input using Javascript

Mr. SirCode In my project: CSSHTML Keyboard, I have installed a keyboard based on an old laptop keyboard, a small project I did as a school homework. The problem is, I'm not sure how to add a specific character to the keyboard, eg: say I click Shift , then A/a

How to send characters to text input using Javascript

Mr. SirCode In my project: CSSHTML Keyboard, I have installed a keyboard based on an old laptop keyboard, a small project I did as a school homework. The problem is, I'm not sure how to add a specific character to the keyboard, eg: say I click Shift , then A/a

How to send value to javascript from input field

crazy developer I need to send an input field "data validation" to a javascript function. the form is <input type="text" name="fname" id="fname" data-validation="length" onchange="validate(this);" required /> JavaScript is function validate(value) {

How to send value to javascript from input field

crazy developer I need to send an input field "data validation" to a javascript function. the form is <input type="text" name="fname" id="fname" data-validation="length" onchange="validate(this);" required /> JavaScript is function validate(value) {

Send HTML input value to JavaScript

possible I don't know what's wrong with my code, it doesn't work. my controller: public function add_user_driver() { if(!$this->user_permission->check_permission())return; $plate_number = $this->input->post('plate_number');

Send checkbox and text input value to URL string using Javascript

Mark Barabs I have a list of products and each individual product has a checkbox value with a product id like "321". I need to collect values when a product checkbox is checked (multiple checkboxes can be selected). Each product will also have an input text fi

Send checkbox and text input value to URL string using Javascript

Mark Barabs I have a list of products and each individual product has a checkbox value with a product id like "321". I need to collect values when a product checkbox is checked (multiple checkboxes can be selected). Each product will also have an input text fi

How to read value from HTML text input?

Alok I have a very simple contact us form with name email, phone number and submit button. On the "Submit" button, click "I want to send emails to some specific mailIDs". However, after multiple attempts of $GET, $_POST, I can't read the value from the textbox

How to read value from HTML text input?

Alok I have a very simple contact us form with name email, phone number and submit button. On the "Submit" button, click "I want to send emails to some specific mailIDs". However, after multiple attempts of $GET, $_POST, I can't read the value from the textbox

How to get value from input text in javascript

lorenzo456 I am trying to get the value entered by the user, but my code is not working. html <body> <button id="test">test</button> <form> <input type="text" id="test1"> </form> </body> javascript: var text = null; $(document).ready(function(){ text

How to get value from input text in javascript

lorenzo456 I am trying to get the value entered by the user, but my code is not working. html <body> <button id="test">test</button> <form> <input type="text" id="test1"> </form> </body> javascript: var text = null; $(document).ready(function(){ text

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

How to send text with line breaks from user input using PHPMailer

Ben I need to send user's text entered in html format ( textarea) along with email. I use PHPMailer with HTML setup. This is also perfect as I need to embed the logo. The only problem is that the email program that receives the mail ignores the line breaks for

Set dynamic javascript value to html text input using sum

Nix Li Please read the form and javascript carefully. My goal is to get the text input values "a" and "b" and then dynamically set the total integer value to the text input id named "x". How to set dynamic javascript value to html text input? It should also be

Add text from html input as value to mysql using php

Dizzy I was wondering if anyone could help me with my problem? I want to send the value (input text) to mysql database but it is always blank text. I'm a beginner and I think I made a stupid mistake... Code: <form name="form" method="get"> <input type="tex

Add text from html input as value to mysql using php

Dizzy I was wondering if anyone could help me with my problem? I want to send the value (input text) to mysql database but it is always blank text. I'm a beginner and I think I made a stupid mistake... Code: <form name="form" method="get"> <input type="tex

input text from html to javascript

Clay I don't understand how to make and use tables. Can someone give me and example using an external java script which has an input text and a submit button which when clicked does the java script function. I also have some doubts. I need a way if I am not us

input text from html to javascript

Clay I don't understand how to make and use tables. Can someone give me and example using an external java script which has an input text and a submit button which when clicked does the java script function. I also have some doubts. I need a way if I am not us

Retrieve json object value from input text field using javascript

username This is json data -> [{"id":"15aea3fa","firstname":"John","lastname":"Doe"}]. How to iduse only javascript. bad piggy You need to parse the value of the textbox to JSONformat Plain text, // getting value from textbox var data = document.getElementById

Retrieve json object value from input text field using javascript

username This is json data -> [{"id":"15aea3fa","firstname":"John","lastname":"Doe"}]. How to iduse only javascript. bad piggy You need to parse the value of the textbox to JSONformat Plain text, // getting value from textbox var data = document.getElementById