shinjuo
shinjuo

Reputation: 21042

form submit from onclick function

I have a function called formFill() and I want it to submit the form after it is done. Right now the function is ran by an onclick within a div like this:

<div class="stormData" onClick="formFill('11-04-14','11-04-14','TX','none');">11-04-14 - TX</div>

this works fine but I wanted the function to submit the form also so I added document.theform.submit(); to the function and it does not work. Here is my function.

function formFill(a, b, c, d){
        theform.from.value = a;
        theform.to.value = b;
        if(d != "none"){
            theform.kmlFile.value = d;
            theform.hailswath.checked = true;
            document.getElementById("kmlLabel").innerHTML = d;
        }
        for(var i = 0;i < document.getElementById("stateSelect").length;i++){
            if(document.getElementById("stateSelect").options[i].value == c ){
                document.getElementById("stateSelect").selectedIndex = i;
            }
        }
        document.theform.submit();
    }

Upvotes: 0

Views: 938

Answers (2)

James
James

Reputation: 22246

Do you have a form element with name='submit'? If so rename it and your function will work.

Upvotes: 1

ninjagecko
ninjagecko

Reputation: 91159

after you finish doing whatever preprocessing you want to do, you can do:

myForm.submit()

edit: make sure you are calling .submit() on the right object; is your theform object a global variable that is pointing to the correct form element? e.g. you can do document.getElementById('id_of_your_form').submit(); if that works and theform.submit() does not work, you probably want to make sure that your earlier calls to theform.from were working properly

Upvotes: 1

Related Questions