How do I recognize a button push from a different field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andersond
    New Member
    • Feb 2007
    • 110

    How do I recognize a button push from a different field

    I probably didn't ask the question right; but, I have a webpage where agents are entering information about trucks they want insured. I want to break out of a function when a button push occurs.

    As agents are entering units, the first thing we ask for is the model year. This signals the beginning of a new entry. However, when they are finished with vehicle entry they can push a button called "Done with Units." When this occurs I want to break out of the first function and go to the function triggered by the button.

    In other words each field, like the model year, has a function that handles the information received in that field. I want the direction of the program to change if and when the Done with Units button is pushed. How can I recognize that? Is it an "else if?" And, if so, how do I code it?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    as long as the function runs there’s little to do… (maybe except when you check inside the function) but as it seems, it should be enough to break up the function (btw., what does the function do?) in smaller parts, so that you can “break” after each part.

    Comment

    • andersond
      New Member
      • Feb 2007
      • 110

      #3
      Each field has a function that does one thing or another and is called by the onblur event. In most all cases the first thing the function will do is see if the field is blank. In some cases the function will test to verify that the entry was all digits, in the case of a model year, or take the contents of the field, strip it of illegal characters then format it as dollars and cents. There are only a small number of questions asked about each vehicle. For example, I will ask for the model year, the body style, the make and the current value. In most cases the user will push the "Done with Units" button when focus is on the model year field; but, it is not unthinkable that it could occur on a different field. I just don't know how to do an "else if" a button is pushed.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I think you don’t need to check the button while any of the onblur() functions is working (time is too short). after the onblur() the JS is “idle” (waiting for the next action). if in the meantime the button is pushed, it will create a new event/action where you can (de)activate or trigger whatever you want.

        Comment

        • andersond
          New Member
          • Feb 2007
          • 110

          #5
          Right.

          Let's try this again. My onblur function checks for a valid entry in a given field. My button's function redirects action from that field to a new task. As it is, the onblur function redirects focus to the field that was left empty. So, I have to enter bogus information until I find a field or a place in the execution of the program where nothing is check for validity. I want to have an option in the validity checker that will break out of checking the field and redirect the program to do something else. As it is, the program allows the entry of up to 12 vehicles and 12 drivers. If the applicant only has one vehicle and one driver I don't want the user to have to enter bogus information for 11 that don't actually exist. If this was not Javascript I would attempt to capture the last keystroke (pushing the "Done with Vehicles" button) as an option in my onblur function. Let me rephrase my question. Is there a Javascript command/function that captures the last keystroke?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            basically you have to remove the onblur() events from the input fields. Yet I’m not sure* whether the onclick() event of the button is triggered, because you’re stuck in a blur-focus-loop until bogus information is passed. maybe you have to substitute the onblur() event by some other (maybe an onblur() of the <fieldset>).

            * - this would have to be tested

            [EDIT]
            another idea, why don’t you start with one “unit” and let the user decide (via ‘add car’ button) whether he wants to do more?

            Comment

            Working...