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

How can I pass a value from one DTC textbox to another?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi. I have two DTC text boxes on a form. After update of a combo box, I need to pass the value of one of the DTC text boxes to the other. Is this possible?

Thanks,
Rene
 
Hi. I'm having a problem with the DTC button control. I'm trying to get it to insert a recordset on the OnClick event.

Here's my code:

Sub btnSave_onclick()
tblCurrentStatTemp.addRecord
End Sub

After I click btnSave, it acts like it's doing something, but it doesn't.

Thanks,
Rene
 
There are two questions here!

1. Client-Side script 'events'.
2. How to add records to the database.

1. Client-Side code
I assume that you are wanting to pass these values between DTC controls without a server round-trip. In other words, you do not need to fetch a load of information from the database as a result of the combo update.

To accomplish this, you need to add a Sever-Side event 'handler' - even if it is completely empty.... Click the Script Outline tab in the toolbox area - open up the Server Objects & Events part of the tree, and click on your combo box. It should reveal an update 'event'. Double-click this event and it will add the necessary code.

Now, you need to 'trap' this event before it is sent back to the server. To do this, add a PageObject DTC (if you do not already have one). Now in the Script Outline under the Client Objects & Events you will see 'thisPage'. Under this is an event called onbeforeserverevent. Double-click this.

Now you have a Client-Side event that is called BEFORE ALL server side events occur. You can do any form validation here, as well as copying data around your DTC's. Please note - this code is JavaScript NOT VBScript.

First thing is to add two parameters to the event call:

function thisPage_onbeforeserverevent(i_strObject, i_strEvent) {

These tell you which DTC object raised the event, and the event itself (click, update etc.)

Now add the body:

if (i_strObject == 'cmbMyCombo'
&& i_strEvent == 'update') {
//DO SOMETHING!!!
//do NOT return back to the Server...
thisPage.cancelEvent = true;
}
}


Where the DO SOMETHING can handle the copying of DTC text boxes:

with document.thisPage {
//copy a dtc textbox to another textbox
txtTextBox2.value = txtTextBox1.value;
}


- Do NOT forget the document prefix (document.thisPage) or else it fails in NetScrape
- Interdev will NOT include the textboxes in the pop-up helper lists - but they will exist by the time this code runs, honest!

All this seems VERY long winded when compared to plain HTML code - but its only a few mouse clicks and a tiny bit of typing.

Try running this now. View the Source in the Browser to see your client-side code and have a guess at how the events work!


2. Adding records to a database

You need more than just an addRecord (against the recordset). If you have a fill-in form, and want the details stored on submit then...

[option 1]
- Do the addRecord
set the values of the recordset fields to the filled in text-box values
do an updateRecord to commit the data to the database
[option 2]
- instead of addRecord, do addImmediate (read the help!)
addImmediate "col1, col2, col3", array(txt1.value, txt2.value, txt3.value)
[option 3]
- write a stored procedure or SQL that uses parameters as place holders for the column data
Add a Data Environment command called addMyTableRow, like...
...INSERT INTO myTable (col1, Col2) VALUES (?,?)
in your code do
thisPage.CreateDE
DE.addMyTableRow txt1.value, txt2.value
[option 4]
- add a record, show a screen, do update...
do addRecord, as before, but then show the page for filling in. The DTC's should be 'bound' to the recordset columns.
when the submit button is pressed, perform the updateRecord command. This causes all bound text-boxes to tell the recordset of any changes, and then updates the recordset. Set any 'fixed' values (those not bound to text boxes) to the appropriate recordset fields before the updateRecord.
[option 5]
- well, I could go on!


Hope you understand some of this, and its of some use. (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top