View Single Post
Old 07-27-2008, 03:43 AM   #2 (permalink)
ryanmr
The Contributor
 
ryanmr's Avatar
 
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 44
Thanks: 3
ryanmr is on a distinguished road
Default

Here's a script with Mootools.
HTML first.
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Quick</title>

  <script type="text/javascript" src="mootools-1.2-core.js"></script>
  <script type="text/javascript" src="mootools-1.2-more.js"></script>
  <script type="text/javascript">
  
  /*
	This uses mootools 1.2.
  */
  
	// global variables so you don't need to redeclare.
	var myRequest = null; 
	var random_input = null;
	
	// domready to set events and define the request object.
	window.addEvent("domready", function(){
		myRequest = new Request({method: 'post', url: 'random.php', onSuccess: myCallBack});
		random_input = $("random_input");
		
		// adding an event to the input field.
				$("random_string").addEvent("click", function(e){
					
					// you can add your arguments here as a query string
					myRequest.send('your=args&right=here');
					e.stop();
					
				});
		
	});
	
	// this is a call back function, adds the returned value from random.php to the input field
	function myCallBack(text, xml) {
		if ( text==null ) {return false;}
		if ( $type(text) == "string" ) {
			random_input.set("value", text);
			// some effects for fun, a highlight of the parent of the input field.
			random_input.getParent().highlight();
		}
	}
	
  </script>
  
</head>
<body>

	<!--
		The input field has the "random_input" id.
		The link has "random_string" id.
	-->

	<form action="" method="post">
		<input type="text" name="myfield" id="random_input" /><br />
		<a href="#" id="random_string">Generate new random string!</a>
		<input type="submit" name="go" value="Go" />
	</form>

</body>
</html>
And my /really/ complex php.
PHP Code:
<?php

    
echo( round(rand() * 100) );

?>
Hope this helps! (Go mootools!)
ryanmr is offline  
Reply With Quote
The Following User Says Thank You to ryanmr For This Useful Post:
delayedinsanity (07-27-2008)