vendredi 25 novembre 2016

Permanently modify checkbox value dynamically via javascript before php form submission

In order to submit a new event along with the user-generated event-date (generated via select/drop-down element), the corresponding checkbox has to be selected after creating/selecting the event-date and converting it to ISO formatted date-string (dt_iso).

This is the code I am executing at the end of the onchange event's function call (for the checkbox having id cbx_e) in order to dynamically modify the checkbox value after selection. But the code does not execute correctly due to undecipherable mistake.

var dt_repl = ";" + dt_iso + ";";
document.getElementById('cbx_e').options[document.getElementById('cbx_e').selectedIndex].value = document.getElementById('cbx_e').options[document.getElementById('cbx_e').selectedIndex].value.replace(";;", dt_repl);

I have attempted the following code also, but no improvement as the code executes erroneously:

var dt_repl = ";" + dt_iso + ";";
document.getElementById('cbx_e').options[document.getElementById('cbx_e').selectedIndex].value.replace(";;", dt_repl);

Also I need advice on whether the checkbox value modified via javascript is really possible to be passed via $_POST variable during form submission.

Note : As the checkbox value for an non-dated event has absent date-field before its date is selected via drop down, I have set its default field value to ";;", and later I want to modify it to something like ";2016-11-26T15:00:00+05:30;" which is the ISO date string.

Thanks.




Aucun commentaire:

Enregistrer un commentaire