Javascript - How can I trigger a button click when a text field has data inputed to it?

This should be pretty simple, I just can't get it. I need a ClickMe command of some type to automatically press a button that is being manually pressed now. The user fields in his name and then presses a button to populate the email, address and phone number fields, I need that button press to be transparent of the user.
circle1dAsked:
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.

Bill-HansonCommented:
Yep, this is an easy one.  Just call the button's click method:

document.formId.buttonId.click();
0
circle1dAuthor Commented:
The text field is named "CallerName", when the field is focused or changed on exited, I need th e"go" button to be pressed. I hate being such a novice, but please provide the code and the placement thereof to get this to function properly so that th euser does not have to press it, nor even see the button
0
Bill-HansonCommented:
Are you sure that you want the button clicked when the field is focused AND when the field value changes?  Normally, you would just click the button when the field value changes.

Either way, it's no problem.  I'll show how to click the button only when the field value changes.  To make it click the button when the field is focused AND when the field value changes, you just need to uncomment one line of code in callerNameOnFocus.

What we are going to do is to save the current field value when the field is focused, then check the value and click the button when the field is exited.  To do this, you'll need to setup 2 functions that will act as event handlers, then just add the event handlers to the <input> tag.

The 2 event handlers will be named callerNameOnFocus and callerNameOnBlur:


      <head>
      <script type="text/javascript">
      
      var savedCallerName = "";
      
      function callerNameOnFocus(){
            savedCallerName = document.forms[0].CallerName.value;
            // document.forms[0].go.click(); // uncomment this line if you really want to click the button each timethat the field is entered.
      };
      
      function callerNameOnBlur(){
            if (document.forms[0].CallerName.value != savedCallerName){
                  document.forms[0].go.click();
            };
            savedCallerName = document.forms[0].CallerName.value;
      };
      
      </script>
      </head>
      

Now, just add the event handlers to your <input> tag:


      <input type="text" id="CallerName" onfocus="callerNameOnFocus()" onblur="callerNameOnBlur()">


That's all there is to it!
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
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!

circle1dAuthor Commented:
What I am doing is utilizing a Domino Name Picker, located here... http://www.codestore.net/store.nsf/unid/FISR-6MPRGU to pick a caller's name from a names.nsf drop down list, once the name has been inputed into the callername field, I click the "go" button to run a DBLOOKUP on that name to populate 3 other fields, email, phone and company. Of course the domino name picker is far to complex for me to figure out what I need to do in order to get the script to populate all the fields without having to run a separate DBLookup for them. I will be accepting your answer tomorrow, but I am giving you the opportunity to look at the code to see if you would like to tackle my issue from the name picker standpoint and if so I will tack on an additional 375 points. Thanks
0
Bill-HansonCommented:
Small world!  I'm a certified Domino developer AND I've implemented a similar name picker in my own web apps.

There are a couple of things that you can do to make your app much cleaner, but I don't have time to explain right now.

One method involves calling a function from the popup instead of setting a field value.

The other method involves calling @DbLookup from JavaScript via AJAX.

Neither technique is very complicated, and will eliminate the button-click workaround.

0
circle1dAuthor Commented:
I gave you a B because you said you had more to offer, but didn't have time to share it, so an A would not be appropriate, thanks.
0
Bill-HansonCommented:
I really don't care about the points that much, but this time, you struck a nerve!

You should not have reduced the grade since the original question (How can I trigger a button click?) was answered clearly and correctly.

I WAS going to assist you with the Domino-specific aspects so that your picker control would really shine.  Now I just don't feel like it.
0
circle1dAuthor Commented:
I have no qualms about your not being able to assist me further, I appreciate your assistance. This is my first time awarding points and only lowered the grade because you said you could have done more. There was no intent to offend and I hope that this experience will not cause you to pass by my name if you should see a question from me in the future. Thanks.
0
Bill-HansonCommented:
No problem, you probably never read the grading guidelines:

"An answer is worth an A, unless it doesn't resolve your issue. If it requires you to do a little more research, or figure out one more piece of code, then it's worth a B. If you think it's not worth a B, the custom is to offer the Experts an opportunity to earn a better grade."
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
JavaScript

From novice to tech pro — start learning today.