<p>Yes you would do this using Javascript so is a little outside the scope of this StackExchange site but here's something that might help get you moving...</p>
<p>Getting the value is easy with something like</p>
<pre><code>document.querySelector('#myElement').value
</code></pre>
<p>You'd need to trigger that in some way, perhaps when the user leaves the field. So (assuming your input has an ID of &quot;myElement&quot;...</p>
<pre><code>document.querySelector('#myElement').addEventListener('blur', function(el){
    let theValue = el.value
})
</code></pre>
<p>What this is doing...</p>
<p>Get the element on the page with an ID of 'myElement'</p>
<p>Adds a listener to it for the 'blur' event (when the user leaves the element)</p>
<p>When that happens it executes a function and passes the element into it</p>
<p>Sets a variable (theValue) with the value of the element.</p>
<p>You now have a javascript variable named 'theValue', but what do you want to do with it?</p>

CC BY-SA 4.0
2020-12-04T10:59:14.523Z
2020-12-04T10:59:14.523Z
foamcow
<p>Alpine JS or the Sprig plugin will help with this.</p>

CC BY-SA 4.0
2020-12-02T17:25:34.880Z
Could you give me a sample code?
Alexis Dalai Waldo Jiménez
CC BY-SA 4.0
2020-12-02T17:18:50.490Z
2020-12-02T17:18:50.490Z
William Hibberd
<p>One way to read a dynamically inserted value is to refresh the page and get it in a twig variable through the url, something like this:</p>
<pre><code>{% set amount = craft.app.request.getQueryParam('amount') %}
</code></pre>
<p>But I am looking for a solution to get a value inserted into an input without refreshing the page, of course, after sending the form (i thing). Do you know if thats possible? Maybe with javascript.</p>

<templating><url><javascript>
How to get an input value without refreshing with twig?
# How to get an input value without refreshing with twig?

(Asked by: username_0 on 2020-12-02)

One way to read a dynamically inserted value is to refresh the page and get it in a twig variable through the url, something like this:
{% set amount = craft.app.request.getQueryParam('amount') %}

But I am looking for a solution to get a value inserted into an input without refreshing the page, of course, after sending the form (i thing). Do you know if thats possible? Maybe with javascript.

**Tags:** templating, url, javascript

---

## 2 answers

### Answer by username_1 on 2020-12-04. Score: 2

Yes you would do this using Javascript so is a little outside the scope of this StackExchange site but here's something that might help get you moving...
Getting the value is easy with something like
document.querySelector('#myElement').value

You'd need to trigger that in some way, perhaps when the user leaves the field. So (assuming your input has an ID of "myElement"...
document.querySelector('#myElement').addEventListener('blur', function(el){
    let theValue = el.value
})

What this is doing...
Get the element on the page with an ID of 'myElement'
Adds a listener to it for the 'blur' event (when the user leaves the element)
When that happens it executes a function and passes the element into it
Sets a variable (theValue) with the value of the element.
You now have a javascript variable named 'theValue', but what do you want to do with it?


---

### Answer by username_2 on 2020-12-02. Score: 1

Alpine JS or the Sprig plugin will help with this.

> **Comments:**
> **username_0**: Could you give me a sample code?  

---

