Surely that will only get the status of the first input, not any of the rest of them? So if you select “Extra Cheese” you would get an indication, but the others don’t have an id. Maybe I’m wrong, maybe my HTML is rusty.
You might be better asking in the JavaScript forum - there’s no PHP in this code.
If this is going to actually be submitted to a processing page, you have given all the checkboxes unique names, so your action page will have to iterate through a pre-determined list of options to see what’s been checked and what hasn’t.
If the checkboxes all have the same name, however, then each ticked checkbox value will be sent as a comma-delimited list of values. (Unless you’re using ColdFusion Server 11 or later, in which case the default setting is to send the values as an array instead of a list.)
Wrong. Each ticked checkbox will be a separate key-value pair in the submitted form data. Whether the used language interprets that as a single value, a comma-separated list, or an array depends on the name of the checkboxes and how the used language interprets these submitted form data.
I have simplified the code that it is simply trying to read the number of pizzas and write it back into the web screen. See below.
<!DOCTYPE html>
<html>
<body>
Number of Pizzas: <input id="element2" name="npizzas" size = "2" type="text" maxlength="2" value="0"/> <br><br>
Enter Number of Pizzas:
<input id="element1" name="nopizzas1" size = "2" type="text" maxlength="2" value=""/>
<br>
Click the button to show the number of pizzas. <br>
<button type="button" onclick="myFunction8()">Show Number of Pizzas in top field</button>
<script>
function myFunction8(){
var np = document.getElementById("element1");
document.getElementById("element2").value = np;
}
</script>
</body>
</html>
The problem is it is unable to get the value entered in the second field and put it in the first field.
What it puts back is: [object HTMLInputElement]
In the very next line of your code, you see that you have to specify the value in order to set the value of the text input. So surely you must use the same to “get” the value of the other text input?
var np = document.getElementById("element1").value;
What you are getting is the entire object that refers to that input element, which contains many attributes. So as @dormilich said, you need to specify which attribute you need.