Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts

    How do I trigger a Form Action using Javascript?

    Hi All,

    I have a flatfile (text) database that I search using a form and submit button. I need to be able to replace/trigger the form search by clicking on an ordinary button, so how can I insert the following form data into a javascript function?

    Gary

    <FORM NAME="Fan Search" ACTION="http://www.domainname.co.uk/cgi/search.pl" METHOD=POST>
    <INPUT TYPE=HIDDEN NAME="EMPTY" VALUE="OK">
    <INPUT TYPE=HIDDEN NAME="DATABASE" VALUE="fans.db">
    <INPUT TYPE=HIDDEN NAME="SRCH_FIELD" VALUE="$3">
    <INPUT TYPE=HIDDEN NAME="KEYWORDS" VALUE="AND">
    <INPUT TYPE=HIDDEN NAME="TEMPLATE" VALUE="fans1.tpl">
    <INPUT TYPE=HIDDEN NAME="SEARCH" VALUE="^Viper$">

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    very simply:

    document.forms.fanSearch.submit()
    document.forms.fanSearch.reset()

    Notice that I put fanSearch, because Fan Search is not valid. You are not allowed a space in there! (You will have to change that in your HTML code)

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Krycek,

    Thanks for the swift reply, it worked a treat using:

    onClick=document.forms.FansSearch.submit()

    inside the tag of the link button

    Now I'm trying to get clever and pass (parse?) one of the search variables to the form when I hit the submit link. I have tried a number of ways I can think of to achieve this but, guess what, no luck.

    Why does this not work?

    onClick=document.forms.FansSearch.submit(input type=hidden name=SEARCH value=^Odyssey$)

    Regards

    Gary

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK Gary, I think we need to start with a couple of basics about forms

    When you submit a form, all the values of all the controls on that form are sent to the page specified in the form's action property.

    So, all those values that you have in hidden inputs will be sent, e.g. empty=ok

    In order to send that search variable, you are going to have to either create a search textbox on the form, and allow someone to type it in, or else submit it yourself by some other means depending on what you want to do.

    If your value is coming from a select box, then the select box should be in your form, along with your hidden elements. When the form is submitted, the value of the select box is sent too, allowing your form handling script to know what item was selected.

    In order to help you with that, I need to know what server-side language you are using to process the form (e.g. PHP, or if I am right and I saw your site somewhere else in the forum, ASP). If you don't want to process the form on the server then you will have to decide on another method.

    Note that the hidden information you are sending is not neccessary. It is a potential security hole to send details of your database through a form - that should be done automatically on the server.

    You should ideally ask on the ASP forum for help with that bit

    ::] krycek [::
    Last edited by krycek; 12-14-2002 at 01:11 PM.
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Krycek,

    OK, I understand so far.

    What I have got already is a search form for my database that uses combo boxes, etc, to set the value of the variables. So if I choose 'fans' I get all of them and if I choose 'fans' and 'brass' I get only the brass fans displayed. As each fan is displayed, its image is displayed also.

    What I want to achieve is to place some images of the fans throughout the site and, when the image is clicked on, the database is searched for that specific item (without needing combo boxes, ext).

    My search routine is a perl script.

    Thanks for your help

    Gary

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think the best way to do this would be to send the variables through the URL.

    For instance, instead of using a form at all, simply make the link on your images go to yoursite/yourcgi.cgi?yourvar=yourvalue&yourvar2=yourvalue2 etc.

    Then, your cgi script will be able to access those variables from the URL (called GET variables) just as easily as from a form (called POST variables) with two advantages:

    1. It will be easy for you to set up your links
    2. People can bookmark their search

    This is a method that is commonly used, just look at sites like Google etc.

    I hope that helps!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #7
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks Krycek - you advice worked perfectly!

    I linked a graphic with:

    http://www.domainname.co.uk/cgi/sear...db&SRCH_FIELD=$3&KEYWORDS=AND&TEMPLATE=fans1.tpl&SEARCH=^Viper$

    and it worked like a charm. I've now got the hang of parsing variables.

    Thanks again

    Gary

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    glad I could help

    btw, what you have done is passing variables, not parsing... parsing is a bit different

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."


  •  

    Posting Permissions

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