How to handle textchanged event of textboxes inside formview using javascript instead of postback to server

I have multiple textboxes inside a formview on a asp.net page. when the text changed on any of the textbox, I'd like to check the textbox id, and depending on the name of the textbox, i'll get its value, do some calculations and update the text of the target  label or text box with the calculated value. There are lots of them so I'd prefer to use javascript and do it on the client side instead of using postback and do it on the server side.

I'm new to using javascript, so the more detail, the better.

Thanks in advance for your help.
eecpamericaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BadotzCommented:
Set up an "onchange" handler that accepts the self-reference from the textboxes:

<input id="tb1" onblur="boxtext_blur(this);" value="Textbox 1"></input>
<input id="tb2" onblur="boxtext_blur(this);" value="Textbox 2"></input>
etc.

function boxtext_blur(obj)
{
    id = obj.id // 'tb1' or 'tb2' or ...
    // do whatever you want here
}
0
eecpamericaAuthor Commented:
That great. I can reference the textbox passed into the function.

Now, how do I reference other label and textbox controls in the formview inside the function to set their values? I tried to lookup the id of those controls in the page source view and reference it  but it didn't seem to work.

Thanks much for your help.
0
BadotzCommented:
If each HTML element has an ID - and all ID values *must* be unique - then you can reference each element like this:

var elemA = document.getElementById('tb1');

Now, elemA refers to the input element "tb1", and you can do what you want with it.

In this way, you can "reach out and touch someone", er, some HTML element ;-)

javascript is case-sensitive, so make sure you spell and cap things properly (getElementById, for example).
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

eecpamericaAuthor Commented:
Thanks a lot for your timely reply. It's very helpful.

One more question: the asp label was rendered as html span element,is it possible to set the text of it in the function, if yes,  how? I can set textbox value without problem.
0
BadotzCommented:
You can set the values of DIV and SPAN elements using the innerHTML attribute:

document.getElementById('spanA').innerHTML = 'either plain text or <b><i>HTML</i></b>');
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eecpamericaAuthor Commented:
That did the trick. Thanks again.
0
BadotzCommented:
Since no one else participated in this question, what is the deal?

I have no idea what the point value of the question was before this comment, but if it was more the 250, why be stingy?

Signed,
Confused
0
eecpamericaAuthor Commented:
Your help was greatly appreciated.
0
BadotzCommented:
My confusion stems from this email message:

"The Asker has requested that this question be Closed, with some or all of the points awarded to participating Experts and one of the Asker's comments selected as the solution. If you object to this action, you have seven days to post a comment describing your objection. This will generate a request in Community Support for Moderator review. If no Expert objects, this question will be closed as described above."

Since no one else participated in this question, what is the deal?

I have no idea what the point value of the question was before this comment, but if it was more the 250, why be stingy?

Signed,
Confused
0
eecpamericaAuthor Commented:
Is there a way to check what point was chosen when I opened the question? or is there a way to add more point to it?  I thought it's 250. I'd like to give you all the points give since you've been very helpful and very timely as well. This is the first time I assign points.
0
BadotzCommented:
No worries - I had not seen that message before, and that is the reason for my confusion.

Glad to help ;-)
0
eecpamericaAuthor Commented:
Please give all the points to the expert Badotz who answered the question. He or she deserves it. I may have made mistake when assigning the point. If that's the case. please correct. Thanks.
0
BadotzCommented:
It's OK - save 'em for next time! I have more than enough poinks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.