Javascript form submit

Discussion in 'JavaScript' started by NoamBarz, Sep 8, 2009.

  1. #1
    So I have a javascript function that validaes a form and then submits it.

    The code is something like this:

    var f = document.myform;
    if(f){
    f.action = 'test.php';
    f.method='post';
    f.submit();
    }


    this code works for all browsers except IE6. does anyone know of a workaround?

    I need to use javascript submit because I don't want the form to submit when the user presess "enter".
     
    NoamBarz, Sep 8, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    What's the line failing in IE6?

    In the mean time, you can try:

    
    var f = document.getElementById('myform');
    if (f) {
      f.action = 'test.php';
      f.method = 'post';
      f.submit();
    }
    
    Code (markup):
    Be sure your form tag has id attribute:
    <form action="" name="..." id="myform" ....
    Code (markup):
     
    caprichoso, Sep 8, 2009 IP
  3. SubZtep

    SubZtep Member

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    48
  4. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    or try var f = document.forms[myform];
    If nothing, could you post also related HTML?
     
    lp1051, Sep 8, 2009 IP
  5. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #5
    document.getElementById() is a standard function and work for most navigators out there. Using other syntax, like you proposed is error prone.
     
    caprichoso, Sep 9, 2009 IP