Hello,

The problem I am having is when the following script is executed within my page and the user submits the form, the variables passed to the GET array are duplicated only for the inputs created by my script. I have other inputs in the form that are created within the HTML of the page that work fine (i.e. they only try to pass their value once) but I cannot get my script to work properly. Here is my script:

var segments1 = new Array("Deer","Fish","Trees","Horses","FSU Torches","BR Cardinal");
var prices = new Array("45","50","65","80","95");
function segment_check() {
  for (var i=0; i<document.segment_form.segments.length; i++) {
    if (document.segment_form.segments[i].checked) {
      var j = 1;
      var segments = document.segment_form.segments[i].value;
      //document.getElementById('segment_form').innerHTML = "";
      for (var a=1; a<=segments; a++) {
        document.getElementById('segment_form').innerHTML += "</br>Segment " + a + ": ";
        for (var b=0; b<segments1.length; b++) {
          document.getElementById('segment_form').innerHTML += "<label for='"+j+b+"'><input type='radio' name='segment_type_"+j+"' id='"+j+b+"' value='"+segments1[b]+"' /> "+segments1[b]+"</label>";
        }
        document.getElementById('segment_form').innerHTML += "<label for='"+j+b+"'><input type='radio' name='segment_type_"+j+"' id='"+j+b+"' value='Other"+[b]+"' /> Other**: </label>";
        document.getElementById('segment_form').innerHTML += "<input type='text' name='segment_type_"+j+"' size='10' onFocus='check_other()' />";
        j++;
      }
      document.getElementById('segment_form').innerHTML += "</br><p style='font-size:18'>Subtotal: $"+prices[i]+".00</p>";
    }
  }
}
function check_other() {
  document.getElementById((document.activeElement.name).charAt((document.activeElement.name).length-1)+segments1.length).checked = true;
}

Here is an example of what the url looks like after the form containing this script has been submitted:

fire_ring_order.php?segments=3&segment_type_1=deer&segment_type_1=&segment_type_2=tree&segment_type_2=&etc.

The input (segments) created in my page only submits itself once, while anything created by the script (segment_type_1, segment_type_2, etc.) submits itself twice with the second, blank value overriding the first, correct value.

Any help would be greatly appreciated.

Thanks.

Look at line 9, if your segments value is greater than 1, you will have the same copy of variable inside your 'segment_form'.innerHTML. You are appending the same string up to the number of segments value! Is that what you want??? What is the real purpose of segments value?

It looks like you are creating a RADIO AND a TEXT field with the SAME name every time. Give them different names. For example, try using this for line 15:

document.getElementById('segment_form').innerHTML += "<input type='text' name='txt_segment_type_"+j+"' size='10' onFocus='check_other()' />";

Hielo was correct. The second set of values was due to the fact that my text inputs were named the same as my radio button. I had originally done this in an attempt to synchronize the text inputs with their associated buttons and found out that what I was trying to do was not possible. I forgot to adjust my naming convention afterwards. Thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.