I have a form with some input checkboxes. For example:
<input type="checkbox" name="felhasznal_1" id="felhasznal_1" onclick="felhasznal(this)">
<input type="checkbox" name="felhasznal_2" id="felhasznal_2" onclick="felhasznal(this)">
<input type="checkbox" name="felhasznal_3" id="felhasznal_3" onclick="felhasznal(this)">
I have hidden value for a form:
<input type="hidden" name="felhasznalas" value="">
My form is named like this:
<form method="post" name="ujpartner_ceg" enctype="multipart/form-data" id="ujpartner_ceg">
And I want to add a masked id for the value of felhasznalas. But I have 2 forms with the same inputs, so that’s why I named the forms, and I want to access to them by getelementByid using the form name.
Here is my javascript (generated by php):
function felhasznal() {
document.ujpartner_ceges.getElementById('felhasznalas').value = '|x|';
if (document.ujpartner_ceges.getElementById('felhasznal_1').checked) {
document.ujpartner_ceges.getElementById('felhasznalas').value = document.ujpartner_ceges.getElementById('felhasznalas').value + '1|x|';
}
if (document.ujpartner_ceges.getElementById('felhasznal_2').checked) {
document.ujpartner_ceges.getElementById('felhasznalas').value = document.ujpartner_ceges.getElementById('felhasznalas').value + '2|x|';
}
if (document.ujpartner_ceges.getElementById('felhasznal_3').checked) {
document.ujpartner_ceges.getElementById('felhasznalas').value = document.ujpartner_ceges.getElementById('felhasznalas').value + '3|x|';
}
}
What did i do wrong?
EDIT: I get this error:
TypeError: document.ujpartner_ceges is not a function.
NOTICE: I have a form with the same inputs named ujpartner_magan!
first, I would use document.getElementById without the “ujpartner_ceges.”
and the main problem is that your inputs don’t have IDs, if you use the IDs exactly like the names your function will work as intended.