javascript document.form.submit()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • therjs
    New Member
    • Apr 2006
    • 3

    javascript document.form.submit()

    i am trying to submit the form multipple times
    within a loop, if i have an alert() coded, it works,
    but, when i take the alert() out, it only does the submit the last time through the loop.
    Last edited by therjs; Apr 30 '06, 04:29 AM.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Post the code, by your own admission it is faulty but we will have great trouble divining that fault without site of the code.

    Comment

    • therjs
      New Member
      • Apr 2006
      • 3

      #3
      document.form.s ubmit() code

      Code:
      function doVote() 
      {
      	var index = 0;
      	
      	index = document.f1.numVoteItems.value;
      	
      	document.f1.action="../Parts/GeneralInfo";
          document.f1.actionName.value = "DOVOTE";
          
       	var yesRadio;
      	var noRadio;
      	var j = 1;
      
      	for (var i = 0; i < index; i++) 
      	{
      		eval("yesRadio=document.f1.YesRadio" + j);
      		eval("noRadio=document.f1.NoRadio" + j);
      		
      		eval("res=document.f1.resPartNumber" + i);
      		eval("req=document.f1.reqPartNumber" + i);
      		
      		if (yesRadio.checked == true)
      		{
      			//alert("yes radio is checked");
      			document.f1.reqPartNumber.value = req.value;
      			document.f1.resPartNumber.value = res.value;
      			document.f1.vote.value = "Y";
      			document.f1.submit();
      			//alert('should have done an update');
      		}
      		
      		if (noRadio.checked == true)
      		{
      			//alert("no radio is checked");
      			document.f1.reqPartNumber.value = req.value;
      			document.f1.resPartNumber.value = res.value;
      			document.f1.vote.value = "N";
      			document.f1.submit();
      			//alert('should have done an update');
      		}
      		
      		j = j + 1;
      	}
      }

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        I suspect (although I don't know) that you are running some sort of undefined behaviour. I do not think that you are supposed to be able to submit a single form multiple times because as soon as you submit a form you start loading the result of that submission.

        Quite how you would see the results of multiple submission I am not sure.

        I suspect in the case of having the alerts in that the form being submitted is not being cleared striaght away indavertently allowing it to be submitted multiple times in the version of the browser you are using. I suspect this is a feature rather than designed behaviour and that you are not garunteed that it will always be there in a new version or different browser.

        Looking at you code it looks like all the information required is on the form and without knowing more about what you are trying to achieve I would say that it should be possible to do what you want from a single submit letting the receiving page handle sorting out all the data server side rather than trying to do it client side.

        Comment

        • therjs
          New Member
          • Apr 2006
          • 3

          #5
          well, i think that i need to set up the receiving servlet to handle an array of values, rather than trying to submit the form multiple times.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by therjs
            well, i think that i need to set up the receiving servlet to handle an array of values, rather than trying to submit the form multiple times.
            I agree :)

            Comment

            Working...