Reply
Help! Random Var??
Old 06-26-2005, 02:52 PM Help! Random Var??
Junior Talker

Posts: 4
I am having a bit of a problem, think my best bet is java (i think). I have a search box on my site which has an intial value set like so:

<input name="skey" type="text" value= "Magician" size="20" maxlength="64" onFocus="clearText(this)">

So this would search for magicians (obviously).

But I want to have the initial random 'value' so every time a user comes on the site they have a random serach they could perform, clown, singer etc.. for example
I have tried using php and a bit of java but nothing seems to work? Anybody know which direction I should be going to get this working?
chris_davidsonu is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-26-2005, 05:25 PM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Create a JavaScript array containing all the possible random search words. Then you can write a little function to put in the <body> tag's "onload" event which sets the value of the box randomly to one of those words in the array.
__________________
Free Teacher Websites
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 06-26-2005, 07:10 PM
Christopher's Avatar
Iced Cap

Posts: 3,111
Location: Toronto, Ontario
Something like this.

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Outershift - Administration</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

    <script type="text/javascript">
    var keywords = ["Magician", "Clown", "Singer", "Actor"];

    function setSearchKeyword(id)
    {
        var obj     = document.getElementById(id);
        var rand    = Math.round(Math.random() * (keywords.length - 1) );

        if(!obj)
            return false;

        obj.value = keywords[rand];
        return true;
    }
    </script>
</head>
<body onload="setSearchKeyword('skey')">

<form action="mysearch.php" method="get">
    Search: <input name="skey" id="skey" type="text" value="" size="20" maxlength="64" onfocus="clearText(this)">
</form>

</body>
</html>
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 06-27-2005, 08:45 PM You are the man
Junior Talker

Posts: 4
Hope I can one day repay the favour, worked perfect. You are a star
chris_davidsonu is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help! Random Var??
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13176 seconds with 12 queries