Jump to content

Simple function


jimjimalabim

Recommended Posts

Ok people I'm trying to write a simple function that will pass a blank string back to my form when the clear button is clicked, but for some reason it will not clear my form. I can't figure this out I have written other functions that have worked, but for some reason this has me stumped.  Here is my function

  //function to clear variables
  function clearVars(&$j, &$k) {
    $workValue = ""; 
    $workType = ""; 
    }

 

  $workValue = (isset($_POST['vfld']))?$_POST['vfld']:'';
  $workType = (isset($_POST['tfld']))?$_POST['tfld']:'';
  if (isset($_POST['submit'])) {
  if ($_POST['submit'] == "Clear") {
    clearVars($vfld,$tfld);
  } elseif ($_POST['submit'] == "Calculate") {
    getVars($vfld,$tfld,$calc);
    $continue = testVars();
    if ($continue == "yes") {
      switch ($workType) {
      case "circle":
        calcCircle($workValue);
        break;
      case "square":
        calcSquare($workValue);
        break;
      case "triangle":
        calcTriangle($workValue);
        break;
      }
   }
  }
}
?>

<form method="post" action="hw06.php"
   id="form1" name="form1">
  <p>
  Enter a number here :
  <input type="text" id="vfld" name="vfld"
  value="<?php echo $workValue; ?>"/>
  </p>
  <p>
  This number is:
  <br />
  <input type="radio" name="tfld" value="circle"
  <?php if ($workType == "circle") {
    echo 'checked="checked"'; } ?> />
  : the radius of a circle
  <br />
  <input type="radio" name="tfld" value="square"
  <?php if ($workType == "square") {
    echo 'checked="checked"'; } ?> />
  : the length of one side of a square
  <br />
  <input type="radio" name="tfld" value="triangle"
  <?php if ($workType == "triangle") {
    echo 'checked="checked"'; } ?> />
  : the length of one side of an equilateral triangle
  </p>
  <p>
  <input type="submit" name="submit" value="Calculate" />
  <input type="submit" name="submit" value="Clear" />
  </p>
</form>

<div id="footer">
<pre>This page written by: <cite>The President</cite> ©2011 and beyond</pre>
</div>

</body>

</html>

Link to comment
Share on other sites

clearVars() takes $j and $k as arguments, but it then modifies $workValue and $workType.  Did you mean to have it take $workValue and $workType as arguments?

 

Another alternative is to simply not set $workValue and $workType in the first place when $_POST['submit'] == "Clear".  Then you don't need to call a function to clear them.  Yet another option is to do the clearing in javascript.

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.