How to read all the entered input values comma separated. Here i am trying to set html using dangerouslySetInnerHTML. The html contain three input field, how can i read valued entered in all the three input field.
Suppose I entered 24 in first input field then 12 in second input field and 2 in third input field . So now i want to save all the values in state variable comma separated i.e.
24,12,2
import React, { useState } from "react";
import "./styles.css";
const data = {
htmltag: `<div><p><input type = 'text' /></p><p><input type = 'text' /></p><p><input type = 'text' /></p></div>`
};
export default function App() {
const [state , setState] = React.useState("")
const handleChange = () => {
setState(prev => ({
...prev,
state:
}));
}
return (
<>
<div onChange = {handleChange}
dangerouslySetInnerHTML={{ __html: data.htmltag }}
/>
<button> Submit </button>
<p>values comma separated: {state} </p>
</>
);
}
datacome from an external source? Do you control what HTML is in there?nameproperty to each input field?