Javascript get and assign values from form fields

vdneut 08 Feb, 2023
I'm looking for the Javascript syntax to get the value from and assign a value to:
- A plain form field like a text field
- A form field read from the database like {Model.field_name}
- A variable available when the Set Models Data in the Read data action is set.

Any lead on one of the above is highly appreciated!
wbuk 12 Feb, 2023
Answer
3 Likes
Where is the javascript getting the value from? It needs to be already rendered on the page for the script to get the value and assign it elsewhere (eg the value is in a div somewhere on the page).

Let's say your page looks like this:


<div id="value">1234</div>
<input type="text" name="amount" id="field">


To retrieve it from the div and place it into input field:


let val = document.getElementById("value").innerText;
document.getElementById("field").value = val;
vdneut 18 Feb, 2023
Oh, my, I feel like a beginner... Maybe I am🙂
Thanks!
You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger