1

Javascript function ASP <body onload="form1.submit();"> is not submitting the form below once the page have loaded.

    <script type="text/javascript">
        $(function() {
            var count = 20;
            $.extend($.wordStats.stopWords, {'retrieved': true, '2007': true});
            $.wordStats.computeTopWords(count);
   var msgsubmit = '<input type="submit" name="button" id="button" value="Submit" />'
   var msgform = '<html><body onload="form1.submit();"><form id="form1" name="form1" method="post" action="get_page_2.asp">\n'
            var msg = 'Keywords: <textarea name="g_seo_no_keywords" id="g_seo_no_keywords" cols="120" rows="3">';
   var msgend = '</textarea>\n';
   var msgg_seo_no_title = '<input type="text" name="g_seo_no_title" id="g_seo_no_title" value="title" />'
   var msgg_seo_no_title_count = '<input type="text" name="g_seo_no_title_count" id="g_seo_no_title_count" value="0" />'
   var msgg_seo_no_keywords_count = '<input type="text" name="g_seo_no_keywords_count" id="g_seo_no_keywords_count" value="0" />'
   var msgg_page_no = '<input type="text" name="g_page_no" id="g_page_no" value="<%=(Request.Form("g_page_no"))%>" />'
   var msgg_page_site = '<input type="text" name="g_page_site" id="g_page_site" value="<%= Request.Form("g_page_site") %>" />'
   var msgg_page_url = '<input type="text" name="g_page_url" id="g_page_url" value="<%= Request.Form("g_page_url") %>" />'
   var msgcounttext = 'Word Count: <input type="text" name="g_seo_no_description_count" id="g_seo_no_description_count" value="<%= counttext %>" />\n';
   var msgg_seo_no_textcount = 'Word Count: <input type="text" name="g_seo_no_textcount" id="g_seo_no_textcount" value="<%= counttext %>" />\n';
   var msgcounttext1 = '<textarea name="g_seo_no_description" id="g_seo_no_description" cols="120" rows="15"><%=completehtml%></textarea>\n'
            for(var i = 0, j = $.wordStats.topWords.length; i < j && i <= count; i++) {
               msg += $.wordStats.topWords[i].substring(1) + ', ';
            }
   var msgformend ='</form></body></html>\n'
            document.write(msgform)+document.write(msg)+document.write(msgend)+document.write(msgg_page_no)+document.write(msgg_page_site)+document.write(msgg_page_url)+document.write(msgg_seo_no_textcount)+document.write(msgg_seo_no_title)+document.write(msgg_seo_no_title_count)+document.write(msgg_seo_no_keywords_count)+document.write(msgcounttext)+document.write(msgsubmit)+document.write(msgcounttext1)+document.write(msgformend);
            $.wordStats.clear();
        });
        </script>

Hi There I am hoping that someone can help me to find the solution why this form is not getting submitted when the page loads.

How would I go about to submit this page? It is supposed to be an autosubmit

Thanks

5
  • just curious... do you have to make the page like this? this seems massively convoluted if you just want to submit a form to the server. Commented Sep 18, 2010 at 13:54
  • 1
    Do you absolutely need to create the markup via js? Commented Sep 18, 2010 at 13:59
  • Hi Guys - The document write is the problem - I think - is there another way that I can pass the document.write to the page or a form on the page? instead of creating a new "js" page? I have done it before but for some reason I cannot remember how I did it... Commented Sep 18, 2010 at 14:03
  • 1
    Ugh, serious escaping problems here. Imagine what a ', " or < would do in those strings. Don't stuff strings together like this, you're making an unmaintainable, XSS-vulnerability-ridden mess. Commented Sep 18, 2010 at 14:12
  • Hi Bobince I am using a regex prior to it that strippes out everything non text... Commented Sep 18, 2010 at 14:17

2 Answers 2

2

Try using document.form1.submit() or document.forms.form1.submit() instead

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

3 Comments

Hi Crayon thanks for the tip, I have tried it but it does not seem to work it feels like the document.write part is creating a second page (on the same page) but disabling (scripts) to render on the page... not sure if it makes sense..
Ah ha! - if you are running this as part of code on an existing page then it will not work! the onload event has already occurred.
Hi Crayon I have used the example that you have provided in the last part of the code document.write(msgform)+document.write(msg)+document.write(msgend) I have added the document.form1.submit() there and now it works, instead of adding it in the <body onload="form1.submit();"> - Thanks for everybody's input it helped me solve this problem in under 30 minutes :-) :-)
0

After this line

    $.wordStats.clear();

try

$("#form1").submit();

1 Comment

Hi JapanPro tried it but it does not seem to work - please see my answer to Crayon Below...

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.