Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106176

Javascript in html card

$
0
0

Hi everyone,

I’m working on a custom HTML and JavaScript setup in Home Assistant, but I’m struggling to retrieve the value of a form field. I believe it has something to do with shadowRoot, which is beyond my current understanding. My goal is to get the value of the form field when a button is clicked. Could someone help me with this?

Here’s my current code:

type: custom:html-template-card
ignore_line_breaks: true
content: >
  <form>
    <label for="fname">First name:</label><br>
    <input id="test_fname" type="text" id="fname" name="fname"><br>
    <label for="lname">Last name:</label><br>
    <input id="test_lname" type="text" id="lname" name="lname"><br>
    <input type="button" value="Submit" onClick="alert('Value: ' + document.getElementById('test_fname').value);" />
  </form>

Any guidance would be greatly appreciated!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106176

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>