SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Quick question about forms

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    Perth
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick question about forms

    Is there a way to submit a form, using a text link, instead of a submit button?

    Thanks!

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes, you can use Javascript to accomplish that. However, a solution like that would only work for those who have Javascript enabled. Those who have disabled it will (probably) not be able to use the form correctly.

    HTML Code:
    <script type="text/javascript">
     function submitForm(sFormId)
     {
       if( document.forms[sFormId] )
         document.forms[sFormId].submit();
     }
    </script>
    HTML Code:
    <form id="foo" action="quicktest.html" method="get">
     <input type="hidden" name="foo" value="bar" />
     <a href="#" onclick="submitForm('foo')">submit</a>
    </form>
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Wizard realestate's Avatar
    Join Date
    May 2004
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess depending on what you are doing you can get the same effect. Our site has a search button on search page which is a form send. A few months ago visiting some dynamic url would give the same result. But you if you are adding values to form before submitting, link won't work. I am not an expert but I think I gave a correct answer.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As lilleman said, you can do it with JavaScript, but that raises accessibility issues.
    An alternative way might be to use an <input&#160;type="submit"> element, and style it to look like an ordinary link using CSS. You may run into trouble in IE if you want to use the :hover pseudo-class, but that could be resolved with JavaScript onmouseover events. (Not as much of an accessibility issue, since it's only styling, whereas not being able to submit at all is a definite barrier.)

    Code:
    /* For CSS2-compliant browsers */
    input[type="submit"] {
      padding:0;
      border:0;
      background:transparent;
      color:#00c;
      text-decoration:underline;
    }
    (For IE, you'd probably have to use a class, since it doesn't understand attribute selectors.)

    The text-decoration doesn't seem to work in Mozilla 1.7.5 or Opera 8, but you could use a bottom border instead.
    Birnam wood is come to Dunsinane

  5. #5
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by AutisticCuckoo
    (For IE, you'd probably have to use a class, since it doesn't understand attribute selectors.)
    One way to fix that would be to use the IE7 "patch".
    ERIK RIKLUND :: Yes, I've been gone quite a while.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •