Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 4
Trades: 0
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
 
 
Register now for full access!
Old 06-26-2005, 05:25 PM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 06-26-2005, 07:10 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
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>
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 06-27-2005, 08:45 PM You are the man
Junior Talker

Posts: 4
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.13232 seconds with 12 queries