views:

608

answers:

3

I'm using a javascript function to submit my form. This works in every browser except safari and I can't figure out why

My javascript function looks like this

function submitForm() { 
    var selectBox = '';
    sel_guide_options = document.subForm.sel_guides;

    if (sel_guide_options.type == "select-multiple") {
         for (var i = 0; i <sel_guide_options.options.length; i++) {
              sel_guide_options.options[i].selected = true;
         }
    } 

    document.subForm.submit();
}

and in my form I use this

<input type="submit" name="btnSubmit" value="#modification_type# #page_item#" id="btnSubmit" onclick="submitForm();">
A: 

Try changing the form element from a type="submit" to type="button". Both should work but it's worth a try.

Ken Aspeslagh
I tried that but it still doesn't submit.
If you take everything out of the function except the submit() call, does it still not submit?
Ken Aspeslagh
Nope, it still won't submit with nothing in the function except the submit() call
I seemed to have fixed it usingdocument.subForm['0'].submit();instead of document.subForm.submit();No idea why that would make a difference but its not giving me any problems now. Works on the other browsers too.Thanks for the help!
very odd. Glad you got it working.
Ken Aspeslagh
A: 

does document.subForm.sel_guides point to a select list?

if so I would revise your code to (presuming subForm is the name of your form):

function submitForm() { 
    var selectBox = '';
    var sForm = document.forms['subForm'];
    sel_guide = sForm.elements['sel_guides'];

    if (sel_guide.type == "select-multiple") {
         for (var i = 0; i <sel_guide.options.length; i++) {
              sel_guide.options[i].selected = true;
         }
    } 
    sForm.submit();
}
scunliffe
Thanks, I will try this out
This didn't really work with the select list, but thanks for the help!
What does the HTML look like for your select list? If you can provide it, I'm sure I can solve this for you.
scunliffe
A: 

I seemed to have fixed it using document.subForm['0'].submit(); instead of document.subForm.submit(); No idea why that would make a difference but its not giving me any problems now. Works on the other browsers too.