SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Multiple forms on one page

    Hi

    I have an html page with multiple forms, I wish to use javascript to check the value of a dropbox (name=os0) and submit if the value is valid.

    If I name the form 'myform' I can use this code


    Code:
     
    <A href="javascript: document.myform.submit();" onclick="if(document.myform.os0.value==56){alert('txt');return false};">Acheter</A>
    However, I do not really want to name each form.

    Is there a way of checking and submitting the forms without explicity naming them, I thought I could do this using something like


    Code:
     
    <A href="javascript: document.this.form.submit();" onclick="if(document.this.form.os0.value==56){alert('txt');return false};">Acheter</A>
    But I'm having no luck.

    Any help appreciated

    Terry
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can refer to the parent form of a form element using the "form" property, for example:
    <input type="button" onclick="this.form.submit();" value="click me" />

    But if you are using the <a> tag, which is not a form element, you'll need a way to identify which form you want to work with, either by use of a name attribute or an id, or by using the form index (0,1,2 etc).

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Arhh, I see, i'd foolishly assumed that because the <a> tag was inside the <form> </form> tags it would refer to that form above the others, I'll have another think, perhaps I'll change the <a> tag for an image and use input type='image' instead

    Thanks for your input

    Terry
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •