Post via hidden input types & javascript won't work...

Discussion in 'Javascript' started by b. hotting, Jan 13, 2006.

  1. b. hotting

    b. hotting Guest

    Hi,

    I don't see why this won't work,
    it are 3 links, the last one (a get) does work, but the first 2 won't.
    i would like to use a post, through hidden input types
    any idea?
    thanks for your help!
    bjorn



    <HTML>
    <HEAD>
    <TITLE>testing...</TITLE>


    <script language="Javascript">

    function fAction(MachineID5, ImageFile5)
    {
    theForm.MachineID.value = MachineID5;
    theForm.ImageFile.value = ImageFile5;
    theForm.submit());
    }
    </script>
    </HEAD>
    <BODY bgcolor="#98D0F8">
    <form action="bbb.php" name="theForm" id="theForm" method="post"
    TARGET="right">
    <input type="hidden" id="MachineID" name="MachineID">
    <input type="hidden" id="ImageFile" name="ImageFile">

    <A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A><br>

    <A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to
    BBB</A><br>

    <A href="bbb.php?MachineID=13&ImageFile='image.jpg'" TARGET="right">Link
    test</A><br>

    </form>

    </BODY>
    </HTML>
     
    b. hotting, Jan 13, 2006
    #1
    1. Advertising

  2. b. hotting wrote:

    > I don't see why this won't work,
    > it are 3 links, the last one (a get) does work, but the first 2 won't.
    > i would like to use a post, through hidden input types
    > any idea?
    >
    > [...]
    > <script language="Javascript">
    > function fAction(MachineID5, ImageFile5)
    > {
    > theForm.MachineID.value = MachineID5;
    > theForm.ImageFile.value = ImageFile5;
    > theForm.submit());
    > }
    > </script>
    > [...]


    theForm.submit());

    should be

    theForm.submit();

    (syntax error, two brackets)

    Hope this helps,

    --
    Bart
     
    Bart Van der Donck, Jan 13, 2006
    #2
    1. Advertising

  3. b. hotting

    b. hotting Guest

    still doesn't work ;-((

    hoped that would do it but it seems its not the only error ;-)



    "Bart Van der Donck" <> wrote in message
    news:...
    > b. hotting wrote:
    >
    > > I don't see why this won't work,
    > > it are 3 links, the last one (a get) does work, but the first 2 won't.
    > > i would like to use a post, through hidden input types
    > > any idea?
    > >
    > > [...]
    > > <script language="Javascript">
    > > function fAction(MachineID5, ImageFile5)
    > > {
    > > theForm.MachineID.value = MachineID5;
    > > theForm.ImageFile.value = ImageFile5;
    > > theForm.submit());
    > > }
    > > </script>
    > > [...]

    >
    > theForm.submit());
    >
    > should be
    >
    > theForm.submit();
    >
    > (syntax error, two brackets)
    >
    > Hope this helps,
    >
    > --
    > Bart
    >
     
    b. hotting, Jan 13, 2006
    #3
  4. b. hotting

    web.dev Guest

    b. hotting wrote:
    > <script language="Javascript">


    The language attribute is deprecated use the type attribute instead:

    <script type = "text/javascript">

    > theForm.MachineID.value = MachineID5;
    > theForm.ImageFile.value = ImageFile5;


    Just a matter of personal preference, I like to use the square bracket
    notation:

    document.forms["theForm"].elements["MachineID"].value = MachineID5;
    document.forms["theForm"].elements["ImageFile"].value = ImageFile5;

    > theForm.submit());


    You have an extra closing parenthesis. You could also try:

    document.form["theForm"].submit();


    > <A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A>


    The use of pseudo javascript protocol is highly frowned upon. Try at
    least using the onclick event handler:

    <a href = "#" onclick = "fAction('1', 'AAA.jpg');">Link to AAA</a>

    > <A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to BBB</A>


    The pseudo javascript protocol has no place in the event handler,
    remove it:

    <a href = "#" onclick = "fAction(6, 'image/BBB.jpg');">Link to BBB</a>

    In the above two links, you'll most likely want to return false so that
    link won't get followed. You should also note, for a graceful
    degradation, you should provide an actual link, in case the user has
    javascript disabled.

    > <A href="bbb.php?MachineID=13&ImageFile='image.jpg'" TARGET="right">Link
    > test</A><br>


    It seems to me that this link doesn't even need to be within the form,
    since you're not submitting the form with this anyway.
     
    web.dev, Jan 13, 2006
    #4
  5. b. hotting

    Lee Guest

    b. hotting said:
    >
    >Hi,
    >
    >I don't see why this won't work,
    >it are 3 links, the last one (a get) does work, but the first 2 won't.
    >i would like to use a post, through hidden input types
    >any idea?
    >thanks for your help!
    >bjorn
    >
    >
    >
    ><HTML>
    ><HEAD>
    ><TITLE>testing...</TITLE>
    >
    >
    ><script language="Javascript">


    should be:
    <script type="text/javascript">


    > function fAction(MachineID5, ImageFile5)
    > {
    > theForm.MachineID.value = MachineID5;
    > theForm.ImageFile.value = ImageFile5;
    > theForm.submit());


    Don't refer to a form simply by its name or id.
    That doesn't work in most browsers.

    document.theForm.MachineID.value = MachineID5;

    or better, pass a reference to the form into the function.

    > }
    ></script>
    ></HEAD>
    ><BODY bgcolor="#98D0F8">
    > <form action="bbb.php" name="theForm" id="theForm" method="post"
    >TARGET="right">
    > <input type="hidden" id="MachineID" name="MachineID">
    > <input type="hidden" id="ImageFile" name="ImageFile">
    >
    ><A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A><br>
    >
    ><A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to
    >BBB</A><br>


    Don't abuse the javascript: pseudo-protocol.
    Don't submit a form via link without good reason.
    Use a normal submit button and set your hidden values in the
    onsubmit handler:

    <form action="bbb.php"
    name="theForm"
    method="post"
    target="right"
    onsubmit="fAction(this,'1','AAA.jpg')">
    <input ...>
    <input ...>
    <input type="submit" value="AAA">
    </form>

    function fAction(f,MachineID5, ImageFile5) {
    f.MachineID.value = MachineID5;
    f.ImageFile.value = ImageFile5;
    }
     
    Lee, Jan 13, 2006
    #5
  6. web.dev wrote:

    > b. hotting wrote:
    >> theForm.MachineID.value = MachineID5;
    >> theForm.ImageFile.value = ImageFile5;

    >
    > Just a matter of personal preference, I like to use the square bracket
    > notation:
    >
    > document.forms["theForm"].elements["MachineID"].value = MachineID5;
    > document.forms["theForm"].elements["ImageFile"].value = ImageFile5;


    It is not only a matter of personal preference. The latter (yours) is
    the standards compliant approach, the former is the proprietary one.

    >> theForm.submit());

    >
    > You have an extra closing parenthesis. You could also try:
    >
    > document.form["theForm"].submit();


    document.form_s_, as above.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 13, 2006
    #6
  7. b. hotting

    Guest

    , Jan 13, 2006
    #7
  8. b. hotting

    b. hotting Guest

    Thanks guys!
    Really appreciated!
     
    b. hotting, Jan 14, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,379
  2. Nick
    Replies:
    4
    Views:
    2,450
    =?Utf-8?B?RWx0b24gVw==?=
    Feb 26, 2006
  3. Rick
    Replies:
    3
    Views:
    8,348
    Alexey Smirnov
    Apr 13, 2010
  4. Walter
    Replies:
    6
    Views:
    251
    Bob Barrows [MVP]
    Sep 17, 2004
  5. Heinz
    Replies:
    1
    Views:
    85
Loading...

Share This Page