Submit HTML form with javascript

Discussion in 'JavaScript' started by NoamBarz, Feb 15, 2009.

  1. #1
    Hi

    I have a form with the action attribute set to a javascript function (action="javascript:DoSomething();"). In my function, after checking that the data was entered properly, I want to submit the form.

    I use something like this:

    var frm = document.frm; (my form)
    if(frm){
    frm.action = 'newpage.php';
    frm.submit();
    }

    There's nothing wrong with this code except that in chrome, nothing happens after I click the submit button for the first time. The form submits only after the second click.

    Any ideas why?
     
    NoamBarz, Feb 15, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    dunno - try adding an alert before and after the if (frm) to see if it sets the object or not. to be honest, try accessing it via id - var frm = document.getElementById("myform");
     
    dimitar christoff, Feb 16, 2009 IP
  3. ranacseruet

    ranacseruet Peon

    Messages:
    302
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think
    this.formname.submit()
    should work fine..
     
    ranacseruet, Feb 16, 2009 IP