SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I would like to set the action property of a FORM tag and then submit the form when an image is clicked. The reason why I want to do it this way is that the ACTION tag already has a property which is used by default. However, when the vistitor clicks a specific image, I want to send the same information (inserted by the visitor) but to a different script.

    How would I go about this? Could someone please be as kind as to give me an example?

    Thanks in advance !
    Sincerely,

    Eirik Johansen
    Netmaking AS

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might work (I might be way off, too):


    Code:
    <html>
    <head>
    <title>Page Title</title>
    <script language=JavaScript>
    var formaction = "page.cgi";
    function change (action) {
    formaction = action;
    }
    </script>
    </head>
    
    <body>
    <form action="<script language=JavaScript>
    document.write(formaction);</script><br>
    <a href="" onClick="change('page2.cgi');">
    <img src="image.gif"></a>
    </body>
    </html>
    I could be wrong, but give that a try. Assuming I didn't screw something up, you should be able to create as many of those image links as you want, changing the form action path for each one.

    Watch Vincent swoop down and school me on this.

  3. #3
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That should work, but i think formaction=action; should be document.form[1].action=action; or something like that...actually i dunno if you can even call up the action property using oop...

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite understand - that command ought to assign the formaction variable whatever "action" contains - so if the link is clicked it'll give that variable a value of "page2.cgi."

    I havn't tried this yet - has anyone else?

  5. #5
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh i get it. I didn't really look at your code to hard. I Thought you were just directly accesing the form action variable, and was thinking that well just assiging a value to formaction wont change the value unless you actually access that perameter. i was thinking you were chanign it like youc an change the contents of a text box. forget my post, i just looked at your code and it should work...

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, ok. I was worried I'd screwed up! I'm kinda sleepy now, so I won't try my code yet (sorry! ), but I'll probably give it a go in the morning if Eirik hasn't tried it by then.

  7. #7
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys,

    Thanks for the helpful replies. I tried out the code, but I can't get it to work. You can take a look at it at http://www.kort.no/index.html?http:/...i-bin/back.cgi (check out the source code for the main frame and the image in the lower right corner marked "SNU").

    Does anyonw have any idea why it doesn't work the way it's supposed to?

    Thanks in advance !
    <Edited by Eirik on 11-29-2000 at 11:43 AM>
    Sincerely,

    Eirik Johansen
    Netmaking AS

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, I don't really know. Can you have a submit button aside from the images? That's the way I originally had it, I guess that would be a pain, but that might be why it doesn't work right now...


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
  •