最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.form.submit(); won't submit in safari - Stack Overflow

programmeradmin7浏览0评论

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();">

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();">
Share Improve this question edited Mar 9, 2010 at 15:49 YOU 124k34 gold badges190 silver badges222 bronze badges asked Mar 9, 2010 at 15:45 user284584user284584 371 gold badge2 silver badges9 bronze badges 2
  • possible duplicate of Firefox handles xxx.submit(), Safari doesn't ... what can be done? – Paul Tomblin Commented Apr 28, 2011 at 16:26
  • stackoverflow./questions/333329/… – Paul Tomblin Commented Apr 28, 2011 at 16:27
Add a ment  | 

3 Answers 3

Reset to default 1

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();
}

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.

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

发布评论

评论列表(0)

  1. 暂无评论