0

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();
    }
1
  • Which browser? And do you get a JavaScript error, and does your page render in quirks mode or standard mode (what's the DOCTYPE)? Commented Apr 18, 2011 at 21:57

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.