.innerHTML - how to make it work ?

Update an input field's displayed and submitted value using JavaScript.

Overview

The issue occurs when using innerHTML to modify an input element, which does not change the field's actual value property.
Use the value property instead of innerHTML to set the text for input fields, ensuring the display updates and the value is included in form submissions.

Answered
ChronoForms v8
ad adam M 14 Jun, 2024

I have a simple form with 2 fields

field1 - text

field2 - html code with some script :

var abc = document.getElementById('field1');

abc.innerHTML = "new value";

I'm afraid the displayed value of field1 is still blank, DOM is not updating :( 

When I "examine" the page with chrome function I can see that field1=new value

<input type="text" name="field1" id="field1" placeholder value autocomplete="off" >new value</input

... but on the display it is still empty, and also when I submit the form, the field1 value is also empty.

How can I update the value of field1 , so that it will be displayed and submitted correctly ?

Max_admin Max_admin 16 Jun, 2024
Answer
1 Likes

you should use

abc.value = "your value"
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ad adam M 16 Jun, 2024
1 Likes

bingo ! problem solved !!!  Thanks a lot :)

This topic is locked and no more replies can be posted.