I want to calculate the price, and if the user checks any checkbox then the value in the corresponding hidden text box is to be added and displayed on the same page before submitting the page,

I do not want to use the hard coded names of text and check boxex because they are dynamically geneated and may differ in number.

I'm generating the check box and text box name by concating the number at the end of string "chkMouse" (used for check box) and string "txtbox" (used for text box).

When i'm displaying the name in alert it seems ok, but when trying to access the value of the text box using that name , it gives an error,

The JS code is attached please help....

Code:
function ug() {
  
  var i = 1;
  var chkBox;
  var txtBox;

  while(i <= document.forms["test"].txtMouse.value) {
    chkBox = new String("chkMouse"+i);
	txtBox = new String("txtMouse"+i);
	
	if(document.forms["test"].chkBox.checked)
	  alert("Checked"+ document.forms["test"].txtBox.value);
	else
	 alert("UnChecked ");
	 
	i++;
  }
  
  //var grossValue = document.forms["test"].h_one.value;

   //alert(grossValue);
  
  //document.forms["test"].out_one.value = grossValue;
}