Skip to content Skip to sidebar Skip to footer

Form If Then Else/ifelse Html On Submit

I have a form that I need to act in specific ways. Example: User brings equipment back: I don't want that to show up in my form. User takes equipment out: I want it to generate to

Solution 1:

Please try this new solution. This will send a post every 30 seconds containing only the input boxes containing text on them.

<!DOCTYPE html><html><head><metaname="Warehouse 3962"content="width=device-width, initial-scale=1.0"><linkhref="style.css"type="text/css"rel="stylesheet"></head><body><sectionclass="w"><divclass="row"><divclass="small columns"><imgsrc="logo.png" /><h3class="green">Users</h3></div><h6>Warehouse 3962</h6></div><divclass="row"><divclass="small columns"><formaction="ajax.php"method="post"id="formSubmit"><tableid="equipment-table"><thead><tr><th>Equipment</th><th>Amount</th><th>Val1</th><th>Val2</th></tr></thead><tbody><?phpforeach ($results['tags'] as$equipment) :
              if ($equipment['category'] === "Part") :
              ?><tr><td><?phpecho$equipment['Amount']; ?></td><tdclass="text-center"><?phpecho$equipment['quantity']; ?></td><td><inputid="<?phpecho$equipment['number'];?>-val1"type="text"name="<?phpecho$equipment['number'];?>-val1"/></td><td><inputid="<?phpecho$equipment['number'];?>-val2"type="text"name="<?phpecho$equipment['number'];?>-val2"/></td></tr><?phpendif;
                endforeach;
               ?><tr><tdcolspan="4"style="text-align: right;"><inputtype="submit"class="button"name="DONE"value="DONE" /></td></tr></tbody></table></form></div></div></section><scripttype="text/javascript">functionsendData() {
      var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
          data = [],
          name, val1, val2;

      for (var i = 0; i < inputs.length; i++) {
        if ( inputs[i].type === 'submit') {
          continue;
        }

        if ( inputs[i].value ) {
          name = inputs[i].name.split('-val');
          val1 = inputs[i].name.split('val1');

          if (val1.length > 1) {
            data.push({name: name[0], val1: inputs[i].value});
          }
          else {
            data.push({name: name[0], val2: inputs[i].value});
          }
        }
      }

      window.setTimeout(function() {
        sendData();
      },30000);
    }

    sendData();
  </script></body></html>

Solution 2:

You cannot mix PHP with JavaScript and why you set a timeout to 1000*30, that is equal to set a timeout to 30000 which means 30 seconds. Then, you can use the 'require' attribute in the input filed to force the user to fill the required information.

<!DOCTYPE html><html><head><metaname="Warehouse 3962” content="width=device-width,initial-scale=1.0"><linkhref="style.css"type="text/css"rel="stylesheet"></head><body><sectionclass="w"><divclass="row"><divclass="small columns"><imgsrc="logo.png" /><h3class="green">Users</h3></div><h6>Warehouse 3962</h6></div><divclass="row"><divclass="small columns"><formaction="ajax.php"method="post"id="formSubmit"><tableid="equipment-table"><thead><tr><th>Equipment</th><th>Amount</th><th>Val1</th><th>Val2</th></tr></thead><tbody>
              <?php
                foreach ($results['tags'] as $equipment) :
                  if ($equipment['category'] == "Part") : ?>

              <tr><td><?= $equipment['Amount']; ?></td><tdclass="text-center">
                  <?php echo $equipment[‘quantity']; ?>
                </td><td><inputid="val1"type="text"name="val1”/>
                </td>
                <td>
                  <input id="val2" type="text"name="val2"/></td></tr>
              <?php
                endif;
                endforeach;
               ?>
              <tr><tdcolspan="4"style="text-align: right;"><inputtype="submit"class="button"name="DONE"value="DONE" /></td></tr></tbody></table></form></div></div></section><scripttype="text/javascript">window.setTimeout(function(){
      var val1 = document.getElementById("val1").value,
          val2 = document.getElementById("val1").value;

      if ( ! val1 && ! val2 ) document.getElement('formSubmit').submit();
    },30000);
  </script></body></html>

Post a Comment for "Form If Then Else/ifelse Html On Submit"