Random Generator Word Generator - PHP -


i'm trying create few random word generators on same page generates verbs, nouns etc. (creating plot generator user can select suggestions randomly generate)

i've managed create it, however, want random word generated stay in box when click generator on same page (for example if click suggest noun , word generated, go click suggest adjective , adjective generates, noun disappears previous box)

<!doctype html> <html> <head> <meta charset="utf-8"> <title>untitled document</title> </head>  <body>  <?php   { {  $noun=array("just", "assume", "there", "are", "lots", "of", "nouns", "in", "here");  //echo rand(0, 2); $myrandom = rand(0, 99); //echo $cars[$myrandom]; //if first name blank/null put  } ?>   <form action="quote.php">     noun<br>     <input type="text" name="firstname"             value="<?php if (isset($_get['noun'])){echo $noun[$myrandom];} }?>"><br>     <input type="submit" name ="noun" value="suggest"> </form>  <?php   { {  $adj=array("just", "assume", "there", "are", "lots", "of", "adjectives", "in", "here");  //echo rand(0, 2); $random = rand(0, 99); //echo $cars[$myrandom]; //if first name blank/null put  } ?>   <form action="quote.php">     noun<br>     <input type="text" name="firstname"             value="<?php if (isset($_get['adjective'])){echo $adj[$random];} }?>"><br>     <input type="submit" name ="adjective" value="suggest"> </form>  </body> </html> 

you can try use ajax instead of writing php , html code in 1 page makes unwieldy.

set ajax call php script return random name , assign name input box. example;

assign id input , button;

<input id='name' name='name' /> <button id="submit">generate random name</button> 

in ajax script, call php script

$( "#submit" ).bind( "click", function() { $.ajax({          type: 'post',            url: "quote.php",            success: function(result){                //assign result input                $('#name').val(result);            }      })   }) 

in php script, generate name in ever way , send result echo.

<?php  //generate random names , other stuff echo $random; 

you can modify in way want.

let me know if helps or if find problem.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -