# Recordset in Javascript

G

#### GTN170777

Hi Guys, thanks for your help yesterday, I've got one more question, then I
think I'm done for now,...

Is it possible to insert recordset data in a javascript, for instance I have
a javascript code that calculates the total price, depending on number of
units, currently what the code does is set the price like so -

if qty 1 then Â£99+VAT

if qty equall to or greater than 2 and equall to or less than 9 then price =
70+VAT calculate total qty by price = total price + VAT

if qty equall to or greater than 10 and equall to or less than 19 then price
= 55+VAT calculate total qty by price = total price + VAT

if qty equall to or greater thar 20 and equall to or less than 50 then price
= 35+VAT calculate total qty by price = total price + VAT

See below

if((numQty >= 1) && (numQty <=
1)){document.getElementById('divPrice').innerHTML = 'Â£' + '99.00' + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' + Math.round(100*(99
* numQty))/100 + ' + VAT';
}
else if((numQty >= 2) && (numQty <=
9)){document.getElementById('divPrice').innerHTML = 'Â£' + '70.00' + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' + Math.round(100*(70
* numQty))/100 + ' + VAT';
}
else if((numQty >= 10) && (numQty <=
19)){document.getElementById('divPrice').innerHTML = 'Â£' + '55.00' + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' + Math.round(100*(55
* numQty))/100 + ' + VAT';
}
else if((numQty >= 20) && (numQty <=
50)){document.getElementById('divPrice').innerHTML = 'Â£' + '35.00' + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' + Math.round(100*(35
* numQty))/100 + ' + VAT';
}

What I would like to do is very similar, however I have 1 price which is
variable and called from a recordset, so for instance lets call the price xx

So my javascript would need to be something like this -

If qty <= 10 price = xx multipled by qty = Total Price
If qty >=11 but <=20 (xx /.9) multipled by qty = Total Price
If qty >=21but <=40(xx /.75) multipled by qty = Total Price
If qty >=41but <=50(xx /.6) multipled by qty = Total Price

of course the code above mine also has this -

innerHTML = 'Â£' + '70.00' + ' + VAT' etc, so again I would need to have
something like innerHTML = 'Â£' + 'qty <= 10 price = xx multipled by qty =
Total Price/ qty..

Does anyone have any ideas?
can this be done?

Thanks Gurus

B

#### Bob Barrows [MVP]

GTN170777 said:
Hi Guys, thanks for your help yesterday, I've got one more question,
then I think I'm done for now,...

Is it possible to insert recordset data in a javascript,

Do you mean "javascript in client-side code" or "javascript in server-side
code"? Either scenario is possible.
for instance
I have a javascript code that calculates the total price, depending
on number of units, currently what the code does is set the price
like so -
See below

if((numQty >= 1) && (numQty <=
1)){document.getElementById

OK, you have some client-side javascript that calculates a value.

What I would like to do is very similar, however I have 1 price which
is variable and called from a recordset, so for instance lets call
the price xx

Is this a server-side recordset? If so, you must be using Response.Write
( said:
Does anyone have any ideas?
can this be done?

So, assuming we are talking about a server-side recordset (which is no
longer in existence at the time your client-side script is running, by the
way) your question seems to be:

"Can I insert data into a server-side recordset using client-side code?"

Let's go back to basics: When an asp file is called from the server, it is
passed to asp.dll, which goes through the file, finding and executing any
server-side code found (code which is between the <5...%> tags, or inside
<script runat="server> blocks), generating the html which is passed to the
client (the browser). As soon as all the html either contained in the file
or generated by the server-side code is passed to the client, it ends the
response and basically moves on to the next file. So, as I hinted at above,
any recordsets that were opened by the server-side code are no longer in
existence (unless the Save method was used to persist them to file on the
server) at the time in which client-side code runs.

So the continuation of the answer is: no server-side code can run using
client-side data unless that client-side data is submitted to the asp file
containing that server-side code.

Now, in case I have misinterpreted your post and you actually are opening a
recordset in your client-side code (in which case I would be flabbergasted
that you would need to ask the quetion), I will not go into any more detail
except to name various techniques for passing client-side data to
load a new page - google should enable you to find a lot of information
about these technologies, post back here if google leaves any of your

1.Use an <img> element, using your client-side code to set the src property
to the appropriate .asp file along with a querystring containing the data
you wish to pass to the server-side code
2. Use a frame or an iframe to load the asp file
3. Use XMLHTTP to submit the data to the asp file
4. Use JSON

HTH,
Bob Barrows

G

#### GTN170777

Hi Bob,

Thanks for the responce, what I should have said is that the page calls the
recordset data on load, the only information in the recordset is the single
unit price, and this is te only variable here, the percentages in the
javascript remain the same, so what I'm really trying to do is calculate the
cost per qty of units based on the set price of one unit multiplied by the
percentage for the number of units.

So hopefully the example below is a little more understandable -

If Qty 1 then XX
If Qty >= 10 but <= 20 then Qty multipled by XX multiplied by 90%
If Qty >=21 but <= 39 then Qty multiplied by xx multiplied by 75%

The value xx has alreadt been called by the recordset..

The javascript in the original post does the calculation and displays the
result on the same page when a button is pressed.

Hope this gives you a little more insight into what I'm trying to achieve.

Thanks once again Bob

B

#### Bob Barrows [MVP]

between client-side and server-side code when you are explaining your
problem to us. In particular, study the part where I talk about the basics.

For example, when you say " ... the page calls the recordset data on load
...." I have no idea if you mean:

"A recordset is opened in server-side code ... "
or
"A recordset is opened in the body's onload event in client-side code ..."

Remember, javascript can be used in both server-side and client-side code.
Saying "the javascript" does not explain anything, unless you preface your
remarks to explain that when you say "the javascript" that you are actually

explanation and I really have nothing to add to what I originally posted.

G

#### GTN170777

Thanks for your input Bob, I've actually managed to do this now, by storing
the variable in a hidden object on a form and then using the following
javascript to process the form -

function OpenWin(url)
{
window.open(url,'win','scrollbars=1,status=0,resizable=0,width=200,height=265');
}

function btnCalculate_onclick()
{
var numQty;

if (isNaN(document.frmClient.txtQty.value))
{
}
else
{
numQty = parseInt(document.frmClient.txtQty.value);

if((numQty >= 1) && (numQty <= 1)){
document.getElementById('divPrice').innerHTML = 'Â£' + adprice + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' +
Math.round(100*(adprice * numQty))/100 + ' + VAT';
} else if((numQty >= 2) && (numQty <= 10)){
document.getElementById('divPrice').innerHTML = 'Â£' +
(Math.round(adprice * numQty)*.8)/numQty + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' +
Math.round(adprice * numQty)*.8 + ' + VAT';
} else if((numQty >= 11) && (numQty <= 20)){
document.getElementById('divPrice').innerHTML = 'Â£' +
(Math.round(adprice * numQty)*.6)/numQty + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' +
Math.round(adprice * numQty)*.6 + ' + VAT';
} else if((numQty >= 21) && (numQty <= 50)){
document.getElementById('divPrice').innerHTML = 'Â£' +
(Math.round(adprice * numQty)*.5)/numQty + ' + VAT';
document.getElementById('maindivPrice').innerHTML = 'Â£' +
Math.round(adprice * numQty)*.5 + ' + VAT';
} else {
}
}
}

Works a treat.

all the best