Use a link for a submit button because of the class being applied

armanbena
armanbena used Ask the Experts™
on
Hi,

I have a submit button, however in order to make the look of the buttons in the site the same, I want to use a class that is being applied for links.  I tried changing the button to a link, but then it does not function properly, because I have a test to see if the button is defined, then it runs an update query after being submitted to the page itself.

<cfset id = #url.id# >
<cfif isdefined("FORM.button") >
            <CFQUERY DATASOURCE="Obi-default"  NAME="UpdateList" >
                  UPDATE NF_WMI
              SET Notes='#form.textarea#'
              WHERE TrackingNumber = '#url.id#'
            </CFQUERY>
           
         <cflocation url="notessaved.cfm" addtoken="no">  
</cfif>

                   <input type="submit" name="button" id="button"  class="button" value="Submit" />
                //this one works, but does not have the class applying
 
              <a href="javascript: document.form1.submit()" class="button" title="Submit" name="button" onclick="javascript:Submit()"> Submit</a> //this is not updating, but has the look I want
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
Take out the href="javascript: document.form1.submit()" because you're already using the onclick event.

You should return false from the onclick handler, too.

Author

Commented:
I tried taking out the href so it is "" and setting the onlick to false, but now instead of going through to the next page I have set using cflocation, it shows the index page.  And it does not save the data.

  <a href="" class="button" title="Submit" name="button" onclick="javascript:Submit(); return false;"> Submit</a>
Most Valuable Expert 2015

Commented:
>> I tried changing the button to a link, but then it does not function properly,
>> because I have a test to see if the button is defined

Just add a field named "button" into your form.  (But since it's not a "button" you might change the name within the code).

       <input name="button" type="hidden" value="used to test form was submitted">

... or change the test to use the name of some other field in your form. Just be sure you're not cfparam'ing that field anywhere.

      <cfif isdefined("FORM.SomeOtherFieldName") >
            <CFQUERY DATASOURCE="Obi-default"  NAME="UpdateList" >
                  UPDATE ... .etc...
            </CFQUERY>
           
         <cflocation url="notessaved.cfm" addtoken="no">  
    </cfif>

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Top Expert 2007

Commented:
Sorry, this:

You should return false from the onclick handler, too.

should have been:

You should return true from the onclick handler, too.
//
function do_submit() {
    var ok = false;
    // Test your values
    // If one of them fails, we cannot submit...
    if (document.getElementById("email").innerHTML !== "") {
        ok = true; // ...otherwise, we can submit
    }
    return ok;
}
//

Open in new window

Then your link becomes:

<a href="" class="button" title="Submit" name="button" onclick="return do_submit();"> Submit</a>
Most Valuable Expert 2015

Commented:
>> make the look of the buttons in the site the same

Just curious, what part of a button's appearance were you unable to change with css?

Author

Commented:
Okay, so using the textarea in the field to test if it is defined will allow me to update my query, but I am not able to get the cflocation to work to go to the next page.  This is what I have:
      <a href="" class="button" title="Submit" name="button" onclick="submit()"> Submit</a>

<cfif isdefined("FORM.textarea") >
            <CFQUERY DATASOURCE="Obi-default"  NAME="UpdateList" >
                  UPDATE NF_WMI
              SET Notes='#form.textarea#',
              Modified_By = #url.uid#,
              Modified_Date =  #Now()#
              WHERE TrackingNumber = '#url.id#'
            </CFQUERY>
         
       <script language="javascript">
        
          window.location.href=notessaved.cfm;
       <!--- <cflocation url="notessaved.cfm" addtoken="no">  --->
       
       
</cfif>
Most Valuable Expert 2015
Commented:
Are you getting an error? As long as the variables exist, this worked fine.  Maybe there's more code we can't see?

<cfif isdefined("FORM.textarea") >
           <!--- use cfqueryparam --->
            <CFQUERY DATASOURCE="Obi-default"  NAME="UpdateList" >
                  UPDATE NF_WMI
              SET Notes='#form.textarea#',
              Modified_By = #url.uid#,
              Modified_Date =  #Now()#
              WHERE TrackingNumber = '#url.id#'
            </CFQUERY>
         
       <cflocation url="notessaved.cfm" addtoken="no">
</cfif>

Author

Commented:
No, I'm not getting an error.  But I cannot get the cflocation tag to go.  Instead of going to notessaved.cfm, it takes me back to the iindex page.  Not sure why?  I tried placing javascript to do it, but that did not work either.  Any suggestions?
Most Valuable Expert 2015

Commented:
>> <cflocation url="notessaved.cfm" addtoken="no">

Sounds like you're doing redirection elsewhere too.  Does notessaved.cfm contain any <cflocation> tags or redirection to the index page?

Author

Commented:
No, this is what I have.        <cflocation url="notessaved.cfm" addtoken="no">
</cfif>

And when I use an input type of button, it was working.  But now that I wish to use this image, and have a class setup for the link, in applying that, now the query works, but I don't understand why it won't go to the notessaved,cfn page.
Most Valuable Expert 2015

Commented:
>> And when I use an input type of button, it was working.  

That wouldn't have any effect on the <cflocation>.  It sounds like something else was changed.  Just guessing now but did your old code have addtoken="no"? What happens if you remove it?

     ie
            <cflocation url="notessaved.cfm">

>> No, this is what I have.

I meant does the "notessaved.cfm" page contain any <cflocation> tags? It's possible your redirect is sending you to => notessaved.cfm  which is then sending you back to the => index page.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial