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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I turn the result of a multiplication in a VALUE that can be entered into a database table ?

Status
Not open for further replies.

leifoet

Technical User
Jan 31, 2016
203
BE
My Javascript multiplication example :
function calculate()
{
  var NUMBER_1 = document.getElementById("NUMBER_2017").value;
  var NUMBER_2 = 34;

  document.getElementById("AMOUNT").value = NUMBER_1 * NUMBER_2;
}
Calculation code from the example :
<input type="text" name="NUMBER_2017" id="NUMBER_2017" onkeyup="calculate()" />
<input type="text" name="AMOUNT" id="AMOUNT" value="">

My calculation (my code)
<input type="text" name="NUMBER_2017" value="<%=rsDATABASE("NUMBER_2017")%>" onKeyUp="calculate()" ></td>
<input type="number" size="12" value="<%=rsDATABASE("AMOUNT")%>" NAME="AMOUNT" >/td>

I must become 2x VALUE (in bold) to insert in the database tabel.
The question is how ?
Thanks for tip - Leif
 
Javascript and ASP vbscript do NOT interact at the same time.


You either have to use AJAX methods to send the value or use javascript to populate a form field value and submit the form to the server.

Chris.

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

Never mind this jesus character, stars had to die for me to live.
 
To clarify my question : if I omit the Javacript code for multiplication (and I manually input the result of the multiplication), this application works good (=send the data to the database)
My problem => I want to transform AMOUNT (= the result of the Java-multiplication) into the bold code below (to 'send' it to the database).

...
rsUpdateEntry.Fields("Number_2017") = Request.Form("Number_2017")
rsUpdateEntry.Fields("AMOUNT") = Request.Form("AMOUNT")
rsUpdateEntry.Fields("XYZ...") = Request.Form("XYZ...")
'Write the updated recordset to the database
rsUpdateEntry.Update
...

Can I do this transition without AJAX ?

Thanks for help - Leif
 
As Chris said, just submit the form after the javascript function updates the "AMOUNT" field, and it should work.
 
Can I do this transition without AJAX ?

Nope

javascript runs AFTER the ASP scripts have completely finished processing and the results have been passed to the client side user agent.

Chris.

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

Never mind this jesus character, stars had to die for me to live.
 
Can I do this transition without AJAX ?

Yep

If "AMOUNT" contains the calculated value, and it's within form tags, and you have a submit button and you click that submit button, then the code Request.Form("AMOUNT") will retrieve that calculated value
 
Are you asking why the javascript does not work?

The example code has id="NUMBER_2017" and id="AMOUNT"

Your code does not, hence getElementById() fails.
 
Indeed, Guitarzan the process in my ASP application is as follows
=> input NUMBER_2017
=> Javascript multiplies this input X 34
(cfr. My Javascript multiplication example in my first question-masseage that I'm trying to implement (!) into my application)
=> the result = AMOUNT
=> this AMOUNT is retrieved (= should be !) by Request.Form("AMOUNT") into the database

BUT : at the moment of pressing the submit button => the application crashes with the error message : Type mismatch
Without the calculation, NUMBER_2017 (= input) -and other applicationfields- are retrieved smoothly to the database.

The transition from Javascript calulation (in)to the ASP code goes wrong.
I might use a non-implementable javascript? Or could it be another problem?

Thans for tips - Leif

 
>at the moment of pressing the submit button => the application crashes with the error message : Type mismatch

Show the applicable ASP / vbscript code around the line that crashes. Hard to offer advice without seeing the code, especially the code that executes after the Submit button is pressed.

Also, did you see rog2y7t6's post above about the "id" maybe not being set?
 
I found the cause of TYPE MISMATCH => a mistype in the JavaScriptfunction in the head : "AMOUNT3 => I apologize

After correction, all the applicationfields are retrieved smoothly to the database, except AMOUNT as the result of the javascript calculation.
I tested the "id" separately from my application - it works.

I refer this to my initial question : how can I become the AMOUNT (= NUMBER_2017 * 34) from JAVA into my application

Javascript
<script type="text/javascript">
<!--
 
function calculate ( ) {
  var NUM_1 = document.getElementById("NUMBER_2017").value;
  var NUM_2 = 34; 

  document.getElementById("AMOUNT").value = NUM_1 * NUM_2;
}

//-->
</script>

My application code for AMOUNT

<tr>
<td><b>Number(2017)</b></td>
<input type="text" name="NUMBER_2017" value="<%=rsDATABASE("NUMBER_2017")%>" onKeyUp="calculate()" size="12" style="font-weight:bold; font-family:arial,sans-serif;
font-size:12px; color:#0000FF; text-align:left; background-color:#E0FFFF;"></td>
</tr>

<tr>
<td height="26"><b>Amount</b></td>
<td height="26" width="353">
<INPUT TYPE="number" size="12" value="<%=rsDATABASE("AMOUNT")%>" NAME="AMOUNT" style="font-weight:bold; font-family:arial,sans-serif;
font-size:12px; color:#0000FF; text-align:right;"><font size="1" color="black">&nbsp;&nbsp;&nbsp;(please do not change)</td>

</tr>

<tr>
<td width="353"><input type="submit" name="Submit" value="Confirm new data"></td></tr>
<tr><td colspan="2"><input type="hidden" name="Nr" value="<% = rsDATABASE("NR") %>"></td></tr>
</form>

Thanks for tips to retrieve also AMOUNT as a result of NUMBER_2017 * 34
Leif
 
...all the applicationfields are retrieved smoothly to the database, except AMOUNT as the result of the javascript calculation.

Then post your code that retrieves the other values besides AMOUNT and saves them into the database. Because you have not shown that yet in any of your posts. In other words, show your code that executes after the Submit button is pressed.
 
The code after submit that rereives and saves the values

<%
Session.LCID = 2067
Dim objCDOMail
Set objCDOMail = CreateObject("CDONTS.NewMail")
... (here comes the code for the e-mail - This email works good - is sent to and received)
objCDOMail.Send
set objCDOMail=nothing

'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsUpdateEntry 'Holds the recordset for the record to be updated
Dim strSQL 'Holds the SQL query for the database
Dim lngRecordNo 'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("Nr"))

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("_private/FXCX.mdb")

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT XYZ17_table.* FROM XYZ17_table WHERE Nr=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the tblComments table using the SQL query held in the strSQL varaiable
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset
rsUpdateEntry.Fields("Workdate") = Request.Form("Workdate")
rsUpdateEntry.Fields("Visitor") = Request.Form("Visitor")
rsUpdateEntry.Fields("NUMBER_2017") = Request.Form("NUMBER_2017")
rsUpdateEntry.Fields("AMOUNT") = Request.Form("AMOUNT")
'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

'Return to the update select page incase another record needs deleting
Response.Redirect "V_list.asp"
%>
<head><title>XYZ17 update_entry_visitMem.asp - 3</title></head>

Thx for help - Leif
 
Are there any more data needed to solve this problem?
Thanks - Leifoet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top