Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help again...

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I need help yet again, although I'm learning great stuff from here and I'm very gratefull. This is the situation:

I load this ASP page with numbers that appear at random (characteristics of a character)

Now I need two buttons, one that will accept the stats and go to menu.asp which I think I've managed to do.
Second one is a reroll button, which in fact should simply reload the screen to get new numbers. Can anyone help me on this? Should I use menu.asp to validate if user clicked the reroll button, what type should that button be?
This is what I have for my asp page, my menu.asp is not finish but if you need it to understand let me know

<%@ Language=VBScript %>
<html>
<form name=frmTT method=post action=menu.asp>
<head>
<title>Gladiators</title>
</head>

<body text=&quot;#000000&quot; bgcolor=&quot;#C0C0C0&quot; link=&quot;#0000EE&quot; vlink=&quot;#FFFF99&quot; alink=&quot;#FF0000&quot;>

<center><font size=+4>Creating your Gladiator's stats</font><font size=+4></font>
<p><font size=+2>Here you may reroll your stats as many times as you wish by pressing the reroll button</font>
<br><br><br>

<%
sql = &quot;select * from races WHERE Race = '&quot; & request.form(&quot;cmbRaces&quot;) & &quot;'&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Glad&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, Conn
%>
<%
Dim Hit, Par, Dod, Dam, Arm, Att, Lif, Sta, Spd, Wil, Cha, HitBns, ParBns, DodBns, DamBns, ArmBns, AttBns, LifBns, StaBns, SpdBns, WilBns, ChaBns
Randomize
HitBns = rs(&quot;Hit&quot;)
Hit = int((rnd * 20) + HitBns + 1)
response.write &quot;Hit: &quot; & Hit & &quot; on possible &quot; & hitbns +20
%>
<br>
<%
Randomize
ParBns = rs(&quot;Par&quot;)
Par = int((rnd * 20) + ParBns + 1)
response.write &quot;Par: &quot; & Par & &quot; on possible &quot; & ParBns +20
%>
<br>
<%
Randomize
DodBns = rs(&quot;Dod&quot;)
Dod = int((rnd * 20) + DodBns + 1)
response.write &quot;Dod: &quot; & Dod & &quot; on possible &quot; & Dodbns +20
%>
<br>
<%
Randomize
DamBns = rs(&quot;Dam&quot;)
Dam = int((rnd * 3) +DamBns + 1)
response.write &quot;Dam: &quot; & Dam & &quot; on possible &quot; & Dambns +3
%>
<br>
<%
Randomize
ArmBns = rs(&quot;Arm&quot;)
Arm = int((rnd * 3) + ArmBns + 1)
response.write &quot;Arm: &quot; & Arm & &quot; on possible &quot; & Armbns +3
%>
<br>
<%
Randomize
LifBns = rs(&quot;Lif&quot;)
Lif = int((rnd * 20) +LifBns + 1)
response.write &quot;Lif: &quot; & Lif & &quot; on possible &quot; &Lifbns +20
%>
<br>
<%
Randomize
StaBns = rs(&quot;Sta&quot;)
Sta = int((rnd * 20) + StaBns + 1)
response.write &quot;Sta: &quot; & Sta & &quot; on possible &quot; & Stabns +20
%>
<br>
<%
Randomize
WilBns = rs(&quot;Wil&quot;)
Wil = int((rnd * 20) + WilBns + 1)
response.write &quot;Wil: &quot; & Wil & &quot; on possible &quot; & Wilbns +20
%>
<br>
<%
Randomize
ChaBns = rs(&quot;Cha&quot;)
Cha = int((rnd * 20) +ChaBns + 1)
response.write &quot;Cha: &quot; & Cha & &quot; on possible &quot; & Chabns +20

%>

<br><br><br>


<div align=center><input type=submit name=cmdAccept value=Accept></div><br><br>

</body>
</form>
</html>


Thanx in advance

Phailak
 
reroll button should look like this:

<input type=button value=&quot;Reroll&quot; onClick=&quot;location.reload();&quot;>

All it will do is act like a refresh button, and reload the page.

:)
Paul Prewett
 
Hail,

Works great but I get following message that can become a nuisance...

&quot;The page cannot refresh without sending the information.
Click retry to resend the information again,
or click cancelto return to the pagethat you were trying to view&quot;

How do I get rid of that message?

Phailak
 
There's no way to get rid of it using this method -- persay

You have to get creative and run two forms in parallel -- one showing that submits to itself, and one hidden, that submits to the following page --

each element of the showing (recursive) form has an onBlur event that sets its counterpart to the same value as itself.

Once you have that all set up, then all you do is submit the form to itself -- which effectively reloads the page with new information -- and so then your button onClick would look like:

onClick=&quot;document.recursiveFormName.submit();&quot;

and **poof** -- no more nag alert --

 
Woah! Way out of my league!

Can't I use redirect somehow?
Is there a way maybe both buttons &quot;Accept&quot; and &quot;Reroll&quot; submit to menu.asp and that once that loads up to know which button the user clicked so that if it was &quot;Accept&quot; everything stays the same but if it was &quot;Reroll&quot; it redirects back to SavingChr? Would that be possible?

Once again I must press that I appreciate all the help...

Phailak
 
Surely --

If you want to record which button was pressed, then you can use a function to submit, and in that function, before you submit, you can set the value of some hidden variable, and then evaluate that element to figure out which was pressed.

ex)
<input type=hidden name=buttonPressed>
<input type=button name=button1 value=button1 onClick=&quot;submitForm(1);&quot;>
<input type=button name=button2 value=button2 onClick=&quot;submitForm(2);&quot;>

<script language=javascript>
function submitForm(value){
document.formName.buttonPressed.value = value;
document.formName.submit();
}
</script>

then evaluate it on the subsequent page like:

<%
dim buttonPressed
buttonPressed = request.form(&quot;buttonPressed&quot;)
if buttonPressed = 1 then
'do whatever
elseif buttonPressed = 2 then
'do whatever
end if
%>

And btw -- don't sell yourself short -- the difference between good programmers and not-so-good programmers is all about what you believe you can do, and what you believe you can't do. But I guess that's true about anything --

good luck! :)
Paul Prewett
 
Ok, that seems good, what would it be in VBscript:

Just want to make sure I get it right, this ASP stuff.
All that is ASP, between <% %> is done before anything else on the page right? So that once the page is loaded, you can't have any events relating to ASP? Is it possible then to use the Script tags to show the results with maybe an OnClick event instead of ASP or am I way off. Let's say something like

When the page loads, use ASP to get data from tables and fill in some variables as before.
Insert script with OnClick event that, let's say, shows those variables on the screen. Each time user clicks reroll, retrieve variable and add a random number before reposting. Is this possible? How would I go about writing the scripts, I believe you wrote to me before about <Script language=vbscript runat server> or something like that? Where should these scripts be inserted, if it's important...

I know I'm asking a lot, but I am making progress, I think ;o)

Phailak
 
Hail Paul,

Yep, me again.
How would I go about saving my data to the recordset, I would of thought I could use rs.edit
rs(&quot;Hit&quot;) = X 'which is my variable

but that's me thinking in VB again, I remember reading that I have to use an sql statement, is that correct? Soemthing like UPDATE or something...

Phailak
 
.edit is dao

you don't have to explicitly tell your recordset you're going to update --

just start assigning values to it, and then call the .update method when you're finished --

If you need to add a new record, then start the whole process off with .addnew and then start adding --

:)
 
DAO, I always come back to that, habit I guess.
Ok, can you open more than one recordset on the same page, because I can't update my recordset but I am using a second recordset I opened, could that be the problem...

(See the words in between ***, there are two instances)

<%@ Language=VBScript %>
<html>
<form name=frmTT method=post action=menu.asp>
<head>
<title>Gladiators</title>
</head>

<body text=&quot;#000000&quot; bgcolor=&quot;#C0C0C0&quot; link=&quot;#0000EE&quot; vlink=&quot;#FFFF99&quot; alink=&quot;#FF0000&quot;>

<center><font size=+4>Creating your Gladiator's stats</font><font size=+4></font>
<p><font size=+2>Here you may reroll your stats as many times as you wish by pressing the reroll button</font>
<br><br><br>

<%
sql = &quot;select * from races WHERE Race = '&quot; & request.form(&quot;cmbRaces&quot;) & &quot;'&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Glad&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, Conn

****Is it wrong to open 2nd recordset?*****

sql2 = &quot;select * from players WHERE UserID = '&quot; & request.querystring(&quot;Player&quot;) & &quot;'&quot;
Set rs2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs2.Open sql2, Conn

***********************************

%>
<%
Dim Hit, Par, Dod, Dam, Arm, Att, Lif, Sta, Spd, Wil, Cha, HitBns, ParBns, DodBns, DamBns, ArmBns, AttBns, LifBns, StaBns, SpdBns, WilBns, ChaBns, Test
Randomize
HitBns = rs(&quot;Hit&quot;)
Hit = int((rnd * 20) + HitBns + 1)
response.write &quot;Hit: &quot; & Hit & &quot; on possible &quot; & hitbns +20

*******Is this wrong or is it because of 2nd recordset?********

rs2(&quot;HIT&quot;) = hit
rs2.update

*************************************************

%>
<br>
<%
Randomize
ParBns = rs(&quot;Par&quot;)
Par = int((rnd * 20) + ParBns + 1)
response.write &quot;Par: &quot; & Par & &quot; on possible &quot; & ParBns +20
%>
<br>
<%
Randomize
DodBns = rs(&quot;Dod&quot;)
Dod = int((rnd * 20) + DodBns + 1)
response.write &quot;Dod: &quot; & Dod & &quot; on possible &quot; & Dodbns +20
%>
<br>
<%
Randomize
DamBns = rs(&quot;Dam&quot;)
Dam = int((rnd * 3) +DamBns + 1)
response.write &quot;Dam: &quot; & Dam & &quot; on possible &quot; & Dambns +3
%>
<br>
<%
Randomize
ArmBns = rs(&quot;Arm&quot;)
Arm = int((rnd * 3) + ArmBns + 1)
response.write &quot;Arm: &quot; & Arm & &quot; on possible &quot; & Armbns +3
%>
<br>
<%
Randomize
LifBns = rs(&quot;Lif&quot;)
Lif = int((rnd * 20) +LifBns + 1)
response.write &quot;Lif: &quot; & Lif & &quot; on possible &quot; &Lifbns +20
%>
<br>
<%
Randomize
StaBns = rs(&quot;Sta&quot;)
Sta = int((rnd * 20) + StaBns + 1)
response.write &quot;Sta: &quot; & Sta & &quot; on possible &quot; & Stabns +20
%>
<br>
<%
Randomize
WilBns = rs(&quot;Wil&quot;)
Wil = int((rnd * 20) + WilBns + 1)
response.write &quot;Wil: &quot; & Wil & &quot; on possible &quot; & Wilbns +20
%>
<br>
<%
Randomize
ChaBns = rs(&quot;Cha&quot;)
Cha = int((rnd * 20) +ChaBns + 1)
response.write &quot;Cha: &quot; & Cha & &quot; on possible &quot; & Chabns +20

%>

<br><br><br>

<div align=center><input type=submit name=cmdAccept value=Accept></div><br><br>

</body>
</form>
</html>


 
No, you can open as many recordsets as you want. The problem is right here:

rs2.Open sql2, Conn

You have accepted the default properties, which includes adReadOnly --

Read my FAQ on the three most important recordset properties. I would have to classify understanding these three properties as the most helpful knowledge I have about basic recordset handling. Once I understood them, I not only started having alot less errors, but started getting much better performance out of my recordsets.

faq333-618

and let me know if that sheds some more light.

:)
paul
 
I think I understand the principle, but I'm still getting an error message. Now I'm guessing, some combinations can't work but I tried different ones and still come to same result, line 23 seems to pass but not 24 or 25 (I switched them around and same message)

sql2 = &quot;select * from players WHERE UserID = '&quot; & request.querystring(&quot;Player&quot;) & &quot;'&quot;
Set rs2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs2.cursortype = adOpenDynamic
rs2.cursorlocation = AdUseServer <----- Line 24
rs2.locktype = AdLockOptimistic
rs2.Open sql2, Conn

Error message:

ADODB.Recordset error '800a0bb9'

The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.

/scripts/gladiateur/SavingChr.asp, line 24

Phailak
 
Did you include the adovbs.inc file that contains the enumerations for those constants???

here's a link to the text of the file:


You can either copy and paste it into a file you save as 'adovbs.inc', or just do a search for it on msdn.microsoft.com --

or just say:
rs2.cursortype = 3
rs2.cursorlocation = 2
rs2.locktype = 3

:)
paul
 
Oh, I had no idea they were constants, thanx I'll check on it later

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top