Jump to content

Loop problem


searls03

Recommended Posts

I am pretty sure the problem I am running into here is within my loop.  But why does the form not submit to the ajax, but it keeps trying to submit to itself?  it is supposed to do ajax...

<?php foreach($_POST["product"] AS $key => $val) {
$product = $val;?>
<script type="text/javascript"><!--
if(document.all && !document.getElementById) { //IE4 support
  document.getElementById = function(id) { return document.all[id]; }
}
function dss_addLoadEvent(fn) {
  if(typeof(fn)!="function")return;
  var tempFunc=window.onload;
  window.onload=function() {
    if(typeof(tempFunc)=="function")tempFunc();
    fn();
  }
}
dss_addLoadEvent(function() {
  if(!document.getElementById) return;
  var f = document.getElementById('form<?php echo $val; ?>');
  // to prevent the form from submitting in this demo
  f.onsubmit = function(){ return false; }
  // hide the textarea and its parent label
  document.getElementById('demo_radio_ta_label<?php echo $val; ?>').style.display = 'none';
  // get a reference to the radio button group
  var rads = f.elements['demo_radio<?php echo $val; ?>'];
  for(var i=0;i<rads.length;i++) {
    // we add the event handler to each button in the group
    rads[i].onkeyup=rads[i].onclick=function(){
      if(!this.checked) return;
      var el = document.getElementById('demo_radio_ta_label<?php echo $val; ?>');
      el.style.display = (this.value=="yes")?'':'none';
    }
    // in case, for any reason, one of the radio buttons is already checked
    rads[i].onclick();
  }
});
// -->
</script>

<form id="form<?php echo $val;?>" name="form<?php echo $val; ?>" method="POST">
Does <?php echo $val; ?> need to be ordered?
  <br />
  <label for="rad1">
<input type="radio" name="demo_radio<?php echo $val;?>" id="rad1<?php echo $val; ?>" value="yes">Yes</label>
<br/>
<label for="rad2"><input type="radio" name='demo_radio<?php echo $val; ?>' id='rad2<?php echo $val; ?>' value='no'> No</label>

</form>
   <div class='label<?php echo $val; ?>' id='demo_radio_ta_label<?php echo $val; ?>'> 
   <script>
$(document).ready(function(){
	$(".myform<?php echo $val; ?>").validate({
		debug: false,

		submitHandler: function(form) {
			// do other stuff for a valid form
			$.post('insert.php', $(".myform<?php echo $val; ?>").serialize(), function(data) {

			});
		}
	});
});
</script><form method="POST" name="myform<?php echo $val; ?>" class="myform<?php echo $val; ?>"> 
  <?php if ((strpos($val,'Sparring') || strpos($val,'Feet')) !== false){
    ?> 

        <input name="item" type="hidden" value="Sparring Feet Size: " />

  <select name="item1">
    <option value="Child 12/13">Child 12/13</option>
    <option value="1/2">1/2</option>
    <option value="3/4">3/4</option>
    <option value="5/6">5/6</option>
    <option value="7/8">7/8</option>
    <option value="9/10">9/10</option>
    <option value="11/12">11/12</option>
    <option value="13/14">13/14</option>
  </select>

  <?php } else if ((strpos($val,'Sparring') || strpos($val,'Hands')) !== false){
    ?> 

    <input name="item" type="hidden" value="Sparring Hands...shoe size: " />
please enter shoe size(hands are based on shoe size) <input name="item1" type="text" />

  <?php } else if ((strpos($val,'Sparring') || strpos($val,'Shins')) !== false){
    ?> 

    <input name="item" type="hidden" value="Sparring shins...shoe size:" />
  please enter shoe size(shins are based on shoe size) <input name="item1" type="text" />
  <?php } else if ((strpos($val,'Sparring') || strpos($val,'head')) !== false){
    ?> 

    <input name="item" type="hidden" value="Sparring Head: size" />
    please keep in mind most people are XL
  <select name="item1">
    <option value="Small">Small</option>
    <option value="Medium">Medium/Lg</option>
    <option value="Large">X-Large</option>
  </select>
  <?php } else if ((strpos($val,'Sparring') || strpos($val,'Elbow Pads')) !== false){
    ?>


    <input name="item" type="hidden" value="elbow pads" />
  <?php } else if ((strpos($val,'Sparring') || strpos($val,'Groin Protector')) !== false){
    ?> 

<input name="item" type="hidden" value="Groin protector size: " />
  <select name="item1">
    <option value='Child Cup Sm (20"-26")'>Child Cup Sm (20"-26")</option>
    <option value='Child Cup Lrg (26"-32")'>Child Cup Lrg (26"-32")</option>
    <option value='Adult Small (26"-32")'>Adult Small (26"-32")</option>
    <option value='Adult Medium (32"-38")'>Adult Medium (32"-38")</option>
    <option value='Adult Large (38"-44")'>Adult Large (38"-44")</option>
    <option value='Adult X-Large (44"-50")'>Adult X-Large (44"-50")</option>
  </select>

  <?php } else if ($val=='Sparring/Ecas Gear:ECAS Gear'){
    ?> 

    <input name="item" type="hidden" value="Ecas Gear size " />

    Shin/elbow
  <select name="shin/elbow">
    <option value="Small">Small</option>
    <option value="Medium">Medium</option>
    <option value="Large">Large</option>
    <option value="X-Large">X-Large</option>
  </select> Shin/elbow
  <select name="glove">
    <option value="Sm/Med">Sm/Med</option>
    <option value="Lg/Xl">Lg/Xl</option>

  </select>
   
  <?php }
  ?>
  <input type="submit" name="hellobob"  value="Submit" />

</form>
     </div>

<?php }
?>

 

Can anyone help?  It is the second form by the way

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.