By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Recordset in Javascript

P: n/a
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
Jul 8 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
GTN170777 wrote:
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 -
<snip - not really relevant>
See below

if((numQty >= 1) && (numQty <=
1)){document.getElementById
OK, you have some client-side javascript that calculates a value.

<snip - not really relevant>
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
(<%= ... %>) to pass the values to the client-side code, correct?
>
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?"

The answer? Not directly.
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="serverblocks), 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
server-side code without unloading the client-side code from the browser 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
questions unanswered:

1.Use an <imgelement, 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 8 '08 #2

P: n/a
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

"Bob Barrows [MVP]" wrote:
GTN170777 wrote:
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 -
<snip - not really relevant>
See below

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

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

<snip - not really relevant>
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
(<%= ... %>) to pass the values to the client-side code, correct?

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?"

The answer? Not directly.
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="serverblocks), 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
server-side code without unloading the client-side code from the browser 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
questions unanswered:

1.Use an <imgelement, 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 8 '08 #3

P: n/a
Please go back and reread what I said, especially about distinguishing
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
talking about the client-side code.

In any event, your clarification really adds nothing to your original
explanation and I really have nothing to add to what I originally posted.

GTN170777 wrote:
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

"Bob Barrows [MVP]" wrote:
>GTN170777 wrote:
>>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 -
<snip - not really relevant>
>>See below

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

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

<snip - not really relevant>
>>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 (<%= ... %>) to pass the values to the client-side
code, correct?
>>>
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?"

The answer? Not directly.
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="serverblocks), 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 server-side code without unloading the
client-side code from the browser 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 questions unanswered:

1.Use an <imgelement, 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 8 '08 #4

P: n/a
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,resiz able=0,width=200,height=265');
}
function btnCalculate_onclick()
{
var numQty;
var adprice;

if (isNaN(document.frmClient.txtQty.value))
{
alert('Please enter a number for advert quantity.');
}
else
{
numQty = parseInt(document.frmClient.txtQty.value);
adprice = parseInt(document.frmClient.adprice.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 {
alert("Please contact us for more information.");
}
}
}

Works a treat.

all the best

"Bob Barrows [MVP]" wrote:
Please go back and reread what I said, especially about distinguishing
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
talking about the client-side code.

In any event, your clarification really adds nothing to your original
explanation and I really have nothing to add to what I originally posted.

GTN170777 wrote:
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

"Bob Barrows [MVP]" wrote:
GTN170777 wrote:
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 -

<snip - not really relevant>

See below

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

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

<snip - not really relevant>

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 (<%= ... %>) to pass the values to the client-side
code, correct?

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?"

The answer? Not directly.
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="serverblocks), 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 server-side code without unloading the
client-side code from the browser 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 questions unanswered:

1.Use an <imgelement, 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 9 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.