Avatar of armanbena
armanbena
 asked on

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

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
ColdFusion LanguageHTML

Avatar of undefined
Last Comment
_agx_

8/22/2022 - Mon
Badotz

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.
armanbena

ASKER
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>
_agx_

>> 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>

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Badotz

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>
_agx_

>> 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?
armanbena

ASKER
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>
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
_agx_

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
armanbena

ASKER
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?
_agx_

>> <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?
armanbena

ASKER
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
_agx_

>> 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.