# Random Number in a Javascript call.

In an asp page I am making a javascript call, one of the parameters is called 'first'. I want to stick a random number in there from 1-10. What's the best way to do this?
Here is the javascript:
<SCRIPT language="JavaScript" SRC="http://context3.kanoodle.com/cgi-bin/context.cgi?id=81257987&db=context&query=small business:office equipment&cgroup=0030bizequip&format=468x60&first=3"></SCRIPT>

So where first=3, it should be first=(1-10).

Thanks!
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:

// Math.random() returns a decimal number between
// 0 and 1.  You multiple the result by the range
// of numbers you want.

// This will generate 0-10.
var rannum = 0
while(rannum == 0) {
rannum = Math.random()*10;
}

// This would generate 145-200
// rannum = Math.random()*55 + 145;

// rannum is now a decimal value, to turn it into
// an integer use Math.round to round it to the nearest
// integer.  Math.floor(rannum) to always round down and
// Math.ceil(rannum) to round up.

rannum = Math.round(rannum);

location.href = "http://context3.kanoodle.com/cgi-bin/context.cgi?id=81257987&db=context&query=small business:office equipment&cgroup=0030bizequip&format=468x60&first=" + rannum

location.href will redirect you to the url specified
Hope this helps
0
Author Commented:
Can you give me the exact syntax? It looks like your solution is in javascript not asp. So how would it look?
Would is be something like this?:

<SCRIPT language="JavaScript"

// This will generate 0-10.
var rannum = 0
while(rannum == 0) {
rannum = Math.random()*10;
}

// This would generate 145-200
// rannum = Math.random()*55 + 145;

// rannum is now a decimal value, to turn it into
// an integer use Math.round to round it to the nearest
// integer.  Math.floor(rannum) to always round down and
// Math.ceil(rannum) to round up.

rannum = Math.round(rannum);

location.href = "http://context3.kanoodle.com/cgi-bin/context.cgi?id=81257987&db=context&query=small business:office equipment&cgroup=0030bizequip&format=468x60&first=" + rannum

SRC=location.href></SCRIPT>
0
Author Commented:
FYI, that gives me back a blank result.
0
Commented:
This is all you need

Take out the src=

just try the following below

------------------------------------------------------------
<SCRIPT language="JavaScript">
var rannum = 0
rannum = Math.random()*10;
rannum = Math.ceil(rannum);

location.href = "http://context3.kanoodle.com/cgi-bin/context.cgi?id=81257987&db=context&query=small business:office equipment&cgroup=0030bizequip&format=468x60&first=" + rannum;
</SCRIPT>
0
Author Commented:
Thanks, but that totally moves me off my asp page. I want the SRC embedded in my page, not taking control of the page.
0
Commented:
I would just use vbScript to generate the random number.  I'm not quite sure why you are using "src" in the javascript or what "src" is used for.

If you could elaberate on this a little more that would be great.

Thanks,
0
Author Commented:
Here is the code on a broader scale.
<% If irsSearchCount Mod 5 = 0 Then %>
<tr>
<td ALIGN="CENTER" COLSPAN="7" BGCOLOR="#FFFFFF"><font FACE="HELVETICA" SIZE="-1">
<hr WIDTH="80%">
<SCRIPT language="JavaScript" SRC="http://context3.kanoodle.com/cgi-bin/context.cgi?id=81257987&db=context&query=small business:office equipment&cgroup=0030bizequip&format=468x60&first=2"></SCRIPT>
<hr WIDTH="80%">
</td>
</tr>
<%
End If
%>

I have tried doing this:

And I get a type mismatch error.
0
Commented:
You can't use asp inside of javascript.

The only reason to use a "src" attribute in a "<script>" tag is to specify an exteral javascript file that you would like to use instead of typeing the javascript in the page itself.  Is that what you are trying to do with the cgi file.

Usually you would use a .js file.

0
Author Commented:
In the documentation there is a parameter called 'first'
by manually changing that we get a variety of ads coming back. You can see this yourself in a browser:

Copy and paste the whole thing in there and change the value for first from 3 to another number and you will see the ad change.

I am trying to pull that 468x60 ad back into my asp page. That's why I am using a javascript call with the src attribute. I admit to not knowing very much about javascript. But it works in the code with the first parameter hard coded, I just want to vary that each time I go and get it again. It doesn't even matter to me if it is 1,2,3,4,5. It just needs to be different every five ads, thus tying it to the mod= 5 portion of the code.

0
Commented:
you can use the asp variables in javascript
type mismatch error is
you forgot "=" sign

you can use asp generated codes in your banner

also
you can use <iframe>your banner</iframe>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.