This is a two part question. Someone answered a similar question the other day (which also contained info about this type of array in PHP), but I cannot find it.
1.
document.form.p_id.length ... not count().
document.form.p_id.length
You really should give your form an id
Then refer to it using:
var theForm = document.getElementById("myform");
Then refer to the elements like:
for(var i = 0; i < theForm.p_id.length; i++){