Jump to content

Recommended Posts

Like i want it to have a set of text boxes that the output values would appear in, for instance the submit button would call to a function or something that would generate a random number for each text box, i would love for it to do this without redirecting or refreshing the page if possible, even the littlest suggestions would help, thank you ahead of time.

Like i want it to have a set of text boxes that the output values would appear in, for instance the submit button would call to a function or something that would generate a random number for each text box, i would love for it to do this without redirecting or refreshing the page if possible, even the littlest suggestions would help, thank you ahead of time.

 

Well, there are two things in play - a sticky form to display the numbers on the same page as the form, and attempting to process the form without a refresh.

 

A sticky form would look something like:

 

<?php
   if(isset($_POST['submit']))
   {
      //invoke random number functions
   }
?>

<!DOCTYPE html>
<html>
   <head>
      <title>Random number generator</title>
   </head>

   <body>
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
         <input type="text" name="text1" value="<?php if(isset($result1)) { echo $result1; } ?>" />
         <br />
         <input type="text" name="text2" value="<?php if(isset($result2)) { echo $result2; } ?>" />
         <br />
         <br />
         <input type="submit" name="submit" value="Click to calculate random numbers" />
      </form>
   </body>

</html>

 

This will cause the page to refresh itself when the submit button is clicked.  If you want the values to appear without any refresh at all, you'd need to use AJAX.

 

Another option is to forgo PHP completely and use JavaScript only.  But, since you asked this in the PHP Coding section, I figured you wanted to see your PHP options.

 

This will cause the page to refresh itself when the submit button is clicked.  If you want the values to appear without any refresh at all, you'd need to use AJAX.

 

 

Well I am kind of new to this whole thing so I'll have to look up into the whole AJAX thing but if you want you can tell me how, otherwise if i run into trouble I'll post a follow up question, thanks for all the help.

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.