i am trying to output form values with inner.html I got 2 problems with my checkboxes: 1. if i check more then 1 checkbox, only one is outputted 2. if no checkbox is checked, the input from other fields are also not outputted How can i fix this problem?
<script>function changeText(){
var userInputname = document.getElementById('name').value;
var userInputcolor = document.querySelector('.color:checked').value;
document.getElementById('output1').innerHTML = userInputname;
document.getElementById('output2').innerHTML = userInputcolor;
return false;
}
</script>
<form method="get" onsubmit="return changeText()">
<input type="text" name="name" id="name" />
<br /><br />
<input type="checkbox" name="color" class="color" value="green">Green<br />
<input type="checkbox" name="color" class="color" value="yellow">Yellow<br />
<input type="checkbox" name="color" class="color" value="red">Red<br />
<input type="checkbox" name="color" class="color" value="blue">Blue<br />
<br /><br />
<input type="submit" value="Output" />
<br /><br />
<b id='output1'></b><br />
<b id='output2'></b><br />
name, but not with the sameid.name[], that many serverside languages understands as an array.