Is there a way to keep 2 textboxes the same???

L

lewis_t

Is there a way have 2 textboxes on the same form where the value of the
first textbox is always the value of the 2nd textbox (even onload)?
 
E

Evertjan.

Is there a way have 2 textboxes on the same form where the value of the
first textbox is always the value of the 2nd textbox (even onload)?

<input id=t1
onkeyup='document.getElementById("t2").value=this.value'>
<br>
<input id=t2
onkeyup='document.getElementById("t1").value=this.value'>
 
E

Evertjan.

Thank you very much for your reply.

Will the onkeyup event get triggered onload?

No, but why should you?

At load time both <input's are empty,

or you van fill them with the same value, like:

<input value='blah'>
<input value='blah'>

or you can fill both by an onload script:

<body onload = 'document.getElementById("t1").value=
document.getElementById("t2").value="blah"'>
 
T

T L

I didn't really explain what I am trying to accomplish... I have a form
with a large table displaying values I extract from a database. I want
to put some final totals from the table at the top of the form (ie:
number of rows with value x). I would rather not create arrarys or
loop thru the ADO recordset to calculate these values then go back
(movefirst) and loop thru again to display. I thought about putting a
hidden textbox at the bottom of the form that would update the textbox
at top of the form. Maybe there is a better way to do this?
 
T

Thomas 'PointedEars' Lahn

Is there a way have 2 textboxes on the same form where the value of the
first textbox is always the value of the 2nd textbox (even onload)?

Quickhack:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function syncInputs(f, name1, name2)
{
var es;
if (f && (es = f.elements)
&& es[name1]
&& es[name2]
&& typeof es[name2].value != "undefined")
{
es[name2].value = es[name1].value;
}
}
</script>
</head>

<body onload="syncInputs(document.forms['form1'], 'text1', 'text2');">
...
<form ... name="form1">
<input name="text1" value="foo"
onchange="syncInputs(this.form, this.name, 'text2');">
<input name="text2">
</form>
...
</body>


PointedEars
 
T

Thomas 'PointedEars' Lahn

T L wrote:
^^^
Hmmm... :)
[...] I have a form with a large table displaying values I extract from a
database. I want to put some final totals from the table at the top of
the form (ie: number of rows with value x). I would rather not create
arrarys or loop thru the ADO recordset to calculate these values then go
back (movefirst) and loop thru again to display. I thought about putting
a hidden textbox at the bottom of the form that would update the textbox
at top of the form. Maybe there is a better way to do this?

I have not used ADO much recently, but I think you want to do a query and
then use the Count property --

<URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>

-- or simply use a variable that you increase as you iterate through the
recordset.


PointedEars
 
T

T L

PointedEars said:
I have not used ADO much recently, but I think you want to do a query and
then use the Count property --

<URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>

-- or simply use a variable that you increase as you iterate through the
recordset.

Yes - it is not the total number of rows (so I can't use ADOrs.Count),
but I have a variable that counts the values of interest. It counts
these values as it gets them from ADO and builds the HTML to display
(ASP).
The problem I am having is when I am done building this HTML table I
want to update a textbox at the top of the form with some totals.
 
R

rkc

T said:
Yes - it is not the total number of rows (so I can't use ADOrs.Count),
but I have a variable that counts the values of interest. It counts
these values as it gets them from ADO and builds the HTML to display
(ASP).
The problem I am having is when I am done building this HTML table I
want to update a textbox at the top of the form with some totals.

If the calculations aren't the result of any user action after the
fact, why don't you just do them using sql on the server?
 
T

Thomas 'PointedEars' Lahn

T said:
Yes - it is not the total number of rows (so I can't use ADOrs.Count),
but I have a variable that counts the values of interest. It counts
these values as it gets them from ADO and builds the HTML to display
(ASP).
The problem I am having is when I am done building this HTML table I
want to update a textbox at the top of the form with some totals.

You do not have to generate the HTML code while you iterate the
recordset, you can concatenate a string that you write later.

Please provide attribution of quoted material.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jasen said:
you could put code in your onload to update the top field.

Following this suggestion would introduce a dependendy on client-side
scripting and DOM features unnecessarily.


PointedEars
 
T

T L

Jasen said:
you could put code in your onload to update the top field.

I tried to link 2 textboxes together in the onload event, like what
Pointed Ears suggested without the ="blah" (because I don't know the
value at that point) but no luck. I assume it is setting textbox 1 to
texbox 2 but at load time both values are blank.
 
T

T L

rkc said:
If the calculations aren't the result of any user action after the
fact, why don't you just do them using sql on the server?

This is the way it works now. It is using ODBC to a VAX Oracle RDB
database. To do the calculations is very expensive and I was trying to
avoid DB hits.
 
T

T L

Thomas said:
You do not have to generate the HTML code while you iterate the
recordset, you can concatenate a string that you write later.

No I don't have to necessarily write the html out while I am iterating
thru the recordset. It will take a little doing but I can defineately
do that. Thanks...
 
V

VK

T said:
I didn't really explain what I am trying to accomplish... I have a form
with a large table displaying values I extract from a database. I want
to put some final totals from the table at the top of the form (ie:
number of rows with value x). I would rather not create arrarys or
loop thru the ADO recordset to calculate these values then go back
(movefirst) and loop thru again to display. I thought about putting a
hidden textbox at the bottom of the form that would update the textbox
at top of the form. Maybe there is a better way to do this?

Why don't you want to use thead and tfoot sections? They are specially
convenient for large databound tables (unless I'm missing some
details).

<table>
<thead>
....
</thead>
<tfoot>
....
</tfoot>
<tbody>
....
</tbody>
</table>

P.S. Yes, thead-tfoot-tbody, this is the right standard endorsed
sequence. You may guess now why ;-)
 
E

Evertjan.

VK wrote on 24 jan 2006 in comp.lang.javascript:
P.S. Yes, thead-tfoot-tbody, this is the right standard endorsed
sequence. You may guess now why ;-)

Thank you for this allowance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top