INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Input Number return info for html display

Input Number return info for html display

(OP)
I have included my html code for many other eyes to help me figure this out.

Javascript works. One side by on_click and other side by on_change.

Issue is when calling my vbscript.

This is a modified version of a working script that just displayed some data a client wanted to see, but now they want to calculate it.

I think I am pretty close but my mind is just so burnt that I could you some helpful advise as to what I am missing.

Thank you
CHAZ



<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<style type="text/css">
input { float: center; }
</style>

<script type="text/javascript">

function Mcalc(){
PRC = 0
AVG = 0

if (document.MARGIN.PPrice.value > "")
{ PRC = document.MARGIN.PPrice.value };
document.MARGIN.PPrice.value = eval(PRC);

if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);

MRG = (PRC - AVG) / PRC * 100;

document.MARGIN.NMargin.value = dm(eval(MRG));
}

function Pcalc(){
MRG = 0
AVG = 0

if (document.MARGIN.PMargin.value > "")
{ MRG = document.MARGIN.PMargin.value };
document.MARGIN.PMargin.value = eval(MRG);

if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);

PRC = AVG/(1-MRG/100);

document.MARGIN.NPrice.value = dm(eval(PRC));
}

function dm(amount) {
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
</script>


</HEAD>
<BODY onLoad="document.MARGIN.txtItem.focus()">

<script language="vbscript" type="text/vbscript">
Function RETRIEVE()

dim dbconnection, sqlrs, itemno, ITEM

Const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMODATA;Data Source=SERVER;password=PASSWORD"

Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")

dbconnection.open CONNECT_STRING

Itemno = document.MARGIN.txtItem.value

sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
If sqlrs.EOF Then
Wscript.Echo "Invalid Item. Please Re-Enter."
Else
document.MARGIN.Description.value = sqlrs("DESCR")
document.MARGIN.AvgCost.value = sqlrs("AVG_COST")
document.MARGIN.Price.value = sqlrs("PRC_1")
document.MARGIN.Margin.value = sqlrs("MARGIN")
END IF

sqlrs.close
dbconnection.close

End Function
</script>


<H3>Margin Calculator</H3><HR>
<FORM method=post action='' NAME="MARGIN">
<table>
<tr>
<td align="left">Item Number:</td>
<td align="left"><INPUT NAME="txtItem" TYPE="TEXT" SIZE="10" autofocus></td>
<td align="left">Item Description: </td>
<td align="left"><INPUT NAME="DESCRIPTION" TYPE="TEXT" SIZE="30" readonly tabindex="-1"></td>
</tr>

<tr>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick ="call RETRIEVE()"></td>
<td align="left"> </td>
<td align="left">Average Cost: </td>
<!-- <td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10" readonly tabindex="-1" ></td> -->
<td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10"></td>
</tr>

<tr>
<td align="left"><BR> </td>
</tr>

<tr>
<td align="left">Current Price: </td>
<td align="left"><INPUT NAME="Price" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">Current Margin: </td>
<td align="left"><INPUT NAME="Margin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>

<tr>
<td align="left"><BR> </td>
</tr>

<tr>
<td align="left">Proposed Price: </td>
<td align="left"><INPUT NAME="PPrice" TYPE="TEXT" SIZE="10" onchange="Mcalc()"></td>
<td align="left">Proposed Margin: </td>
<td align="left"><INPUT NAME="PMargin" TYPE="TEXT" SIZE="10"></td>
</tr>

<tr>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Margin" onclick ="Mcalc()" ></td>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Price" onclick ="Pcalc()" ></td>
</tr>

<tr>
<td align="left"><BR> <BR></td>
</tr>

<tr>
<td align="left">New Margin: </td>
<td align="left"><INPUT NAME="NMargin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">New Price: </td>
<td align="left"><INPUT NAME="NPrice" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>

<tr>
<td align="left"><BR> <BR><BR></td>
</tr>

<tr>
<td align="left"><INPUT TYPE="RESET" STYLE="width:100" VALUE="Clear Form" onclick="document.MARGIN.txtItem.focus()"></td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Copy Data" onclick="document.MARGIN.txtNPrice.select()"></td>
<td align="left">&nbsp; </td>
<td align="left">&nbsp; </td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Exit" onclick="self.close()"></td>
</tr>
</table>


</FORM>
</BODY>
</HTML>

RE: Input Number return info for html display

forum329: VBScript

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Input Number return info for html display

Your client-side code includes the database address, username and password; and could easily be changed to fire any SQL command anybody liked into the database (quite aside from the SQL injection possibilities). I seriously hope you're not intending to deploy this on the open web. I'd also point out that using vbScript instead of Javascript shuts out anybody not using IE.

I'd suggest building a simple web service where you pass in the ItemNo and it returns the relevant values as a JSON object.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd

RE: Input Number return info for html display

(OP)
Chris,

This is an internal app for a pos system. its all self contained.

And they only use IE for the pos system. That what the forms within the system were designed around.

I know, alot of common security is soooo breached, and if I werent learning as I created this I definately would have written it much better.

Still many aspects I need to learn

Thank you.

PROJECT DONE
CLOSED

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close