Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

demonz's avatar

I want to change the state based on index in react and inertia

how do I add the index to onChange event in the select tag.

  const { data, setData, post,delete: destroy, processing, errors, reset } = useForm({
        Attendance_status: [],
    });

 <select name="Attendance_status" onChange={e => setData('Attendance_status', [...data.Attendance_status,e.target.value])}>
                            <option value="present">Present</option>
                            <option value="absent">Absent</option>
                            <option value="late">Late</option>
   </select>

0 likes
1 reply
demonz's avatar

this gives error

<select name="Attendance_status" onChange={(e,index) => setData('Attendance_status', [...data.Attendance_status,data.Attendance_status[index]:e.target.value])}>

Please or to participate in this conversation.