document.form.p_id.length
... not count().
You really should give your form an id
<form id="myform">
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++){