jimjimalabim Posted March 11, 2011 Share Posted March 11, 2011 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 https://forums.phpfreaks.com/topic/230293-simple-function/ Share on other sites More sharing options...
btherl Posted March 11, 2011 Share Posted March 11, 2011 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 https://forums.phpfreaks.com/topic/230293-simple-function/#findComment-1185967 Share on other sites More sharing options...
jimjimalabim Posted March 11, 2011 Author Share Posted March 11, 2011 I know I could not set them, but I'm trying to write a function that will not set, or set them to blank. Link to comment https://forums.phpfreaks.com/topic/230293-simple-function/#findComment-1186016 Share on other sites More sharing options...
Mahngiel Posted March 11, 2011 Share Posted March 11, 2011 couldn't you just use a reset button? <input type="reset" value="reset"> Link to comment https://forums.phpfreaks.com/topic/230293-simple-function/#findComment-1186018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.