SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: how do i...

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do i...

    hi..
    I need urgent help. Please can somebody tell me how can i submit a form through java script. here is what i came up with and its not submiting.. i am a java script newbie so please help!!!

    <script language="JavaScript">
    <!--

    function subm(value)
    {
    document.form2.purchase.value=value;
    document.form2.submit();

    }
    //-->
    </script>

    where form2 is the name of the form. I am calling this funcion on an onclick event on an image.

    <a href='#'onClick='subm("removeitem")'><img src="images/edit.gif" width="60" height="16" border='0'></a>

    please advice

    Khalid
    signature

  2. #2
    SitePoint Addict ThomasAesir's Avatar
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink Coding

    The force will help my young Padwan learner . . . or if that doesn't work then this code should!

    Code:
    <a href="JAVASCRIPT:subm('removeitem')">
    PS the above code should have JAVASCRIPT capitalized and as one word.
    Thomas Oeser - Blueprint Software
    Web Scripting Editor v 5.2 One cool Web editing tool.
    3dcomputergraphics.com Coming Soon!

  3. #3
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding

    Originally posted by ThomasAesir
    The force will help my young Padwan learner . . . or if that doesn't work then this code should!

    Code:
    <a href="JAVASCRIPT:subm('removeitem')">
    PS the above code should have JAVASCRIPT capitalized and as one word.
    1 quick question...

    Why capitalized?

    I use only lowercase and all my scripts run without error.
    Mind you I don't normally put javascripts directly in the href, but prefer to use them onclick.

    1 quick(ish) tip...

    Change the = after the word 'javascript' to its html character equivalent [&amp;&#35;61&#59;] when adding a script to a post and then it won't be seen as a true javascript command and won't be split by the SPF rules.

    In your method just swap the : for &amp;&#35;58;

    The 'script' will still appear correctly in the posting though and you won't need to explain.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  4. #4
    SitePoint Addict ThomasAesir's Avatar
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question javascript

    Your right, I don't think it matters and lower-case may be more accurate. Thank's for the code advice.
    Thomas Oeser - Blueprint Software
    Web Scripting Editor v 5.2 One cool Web editing tool.
    3dcomputergraphics.com Coming Soon!

  5. #5
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Khalid I can't see any reason your code does not work - could you post the HTML (or give us a link to the pagE) so we can see if there is a problem there.

    For the record using javascript: in the href="" part of the a tag is no longer recommended - it is not supported by standards and breaks in browsers that do not support javascript. More information here:

    http://www.scottandrew.com/weblog/000284

  6. #6
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe the way you have used single-quotes and double quotes is causing the problem.

    Perhaps swapping them over would fix it.

    Don't double-quotes have a higher rank than single-quotes?

    I understood it that we should use doubles on the outside and singles within that.

    Maybe I'm wrong, I dunno.

    Perhaps swapping the variable declaration around to...

    value = document.form2.ourchase.value;

    ...will do it.

    It's just a semi-educated guess based on what I'm used to seeing. I'm still learning too.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature


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
  •