3 Replies Latest reply on Sep 10, 2008 12:52 PM by fober1

    Checking to see what button the user pressed.

    Diplomat_Nyc
      Hello to All,

      I have a web page I am trying to create Its a form that allows users to enter in career information . The problem is that I have 1 row shown to the user at a time and when the user presses the (Add new) button, I want another row to appear to let the user enter more career information. I have figured out a way to do this using <cfif IsDefined("FORM.Add")> , But I don't want to send the form to the server, I just want to check the button and then add a new line without a form.submit, because right now I have 2 forms on the page. Is there anyway to check the button pressed without a form submit. Like is there a coldfusion check to see what button has been pressed.


      sample code:





      Thank you.
        • 1. Re: Checking to see what button the user pressed.
          Level 7
          Diplomat_Nyc wrote:
          > Is there anyway to check the button pressed without a form submit.

          Yes.

          > Like is there a coldfusion check to see what button has been pressed.

          NO!

          ColdFusion only runs on the server, it will never know what was happened
          until it receives another request from the client, which would require
          some type of submit.

          You are looking for a client solution. And there are many out there
          that will do just what you are asking to do. Using JavaScript, DHTML
          and possible AJAX techniques, you can easily have the client browser add
          new form elements when a user activates a given control.

          You are going to invoke JavaScript functions to manipulate the DOM
          (Document Object Model). There are several JavaScript frameworks thet
          build this in.

          Hopefully I have given you enough key words to do a successful search
          from the many tutorials and examples on how to do this. Because such an
          explanation is much to larger to fit into the space of this reply.
          • 2. Re: Checking to see what button the user pressed.
            Diplomat_Nyc Level 1
            Thank you very. Well appreciated.
            • 3. Re: Checking to see what button the user pressed.
              fober1 Level 1
              Hi,

              You can add additional rows already on the server in CF, but hide them with CSS, and have the add button just switch them to visible (with a little java script), like in the sample below.

              cheers,
              fober


              <cfset number_of_fields= 15>

              <cfoutput>
              <cfloop index="x" from="1" to="#number_of_fields#">

              <cfif x IS 1>
              <cfset style= "display:block;">
              <cfelse>
              <cfset style= "display:none;">
              </cfif>

              <div id="field#x#" style="#style#">
              <input type="File" name="field#x#"><br>
              </div>
              </cfloop>
              </cfoutput>

              <input type="Button" id="btn_add" onclick="visible_add('field')" value="Add File">

              <script language="JavaScript">
              function visible_add(id){
              var counter= 1;

              do{
              obj= document.getElementById(id + counter);
              if ( obj.style.display == 'none') {
              obj.style.display= 'inline';
              return;
              }
              counter++;
              }while ( document.getElementById(id + counter) != null )

              document.getElementById('btn_add').style.display = 'none';
              }
              </script>