Set the Value of an Input Field

Set the value of an input field

This is one way of doing it:

document.getElementById("nameofid").value = "My value";

Set Value of Input Using Javascript Function

Try...
for YUI

Dom.get("gadget_url").set("value","");

with normal Javascript

document.getElementById('gadget_url').value = '';

with JQuery

$("#gadget_url").val("");

Set value to input field onchange from other input field

Simply assign an identifier to each input, and pass the input to the function:

<input type="text" id="myInput1" onchange="myChangeFunction(this)" placeholder="type something then tab out" /><input type="text" id="myInput2" />
<script type="text/javascript"> function myChangeFunction(input1) { var input2 = document.getElementById('myInput2'); input2.value = input1.value; }</script>

How to set value of form input field?

You can set the attribute value using t-att-value="".

So in my case I should use this input field:

<input type="value" name="partner_id" t-att-value="user_id.partner_id.id"/>

Which does the same as the given example with the <p> and javascript.

Set the value of an input field on change of a field

You should call useState to update values on re-rendering

export default function App() {
const [value, setValue] = useState("0.00") //call useState to re-render UI as well as get new values

function onChange(event) {
setValue(event.target.value) //update your value here
}

return (
<div className="App">
<label>Input Value</label>  
<input
type="number"
step="0.01"
placeholder="0.00"
onChange={onChange}
/>
<br />
<br />
<label>Set Value</label>  
<input value={value} type="number" step="0.01" placeholder="0.00" readOnly />
</div>
);
}

set the value from an input field on my html page in Localstorage

You can save value to localStorage with localStorage.setItem and localStorage.getItem to get localStorage value. Here is the working example.

$(document).ready(function(){    if(localStorage.getItem("inputvalue")){      $('p').text(localStorage.getItem("inputvalue"));    }        $('button').on('click', function() {    localStorage.setItem("inputvalue", $('#text').val());    $('p').text(localStorage.getItem("inputvalue"));});    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><p>Hello</p>
<div class="form-group"> <label for="text">Change title:</label> <input type="text" class="form-control inputBox" id="text" name="text"></div>
<button>submit</button>

How to set an input field value based on the value of another field?

You would set up a change event handler on the select that sets the value of the input:

const $input = $("#size");
$input.change(function(){
$("#count").val($(this).val());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="size" class="" name="attribute_size" data-attribute_name="attribute_size" data-show_option_none="yes">
<option value="">Choose an option</option>
<option value="1" class="attached enabled">Small</option>
<option value="2" class="attached enabled">Medium</option>
<option value="3" class="attached enabled">Large</option>
<option value="4" class="attached enabled">Extra Large</option>
</select>

<input id="count" name="count" value="5" class="thwepo-input-field ">


Related Topics



Leave a reply



Submit