SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having Problem with submit() Method

    I'm having problems with the submit() method of the forms object. I've got a form that submits fine if I use <input type="submit">; it executes an ASP page and redirects back to the same page. Because of the layout of my page, I don't want to put the button in that location, though. Instead, I've tried this:
    Code:
    function submit_form(formIndex) {
    	document.forms[formIndex].submit();
    	return true;
    }
    and put this in my HTML:
    Code:
    <form name="submit_button" onsubmit="return submit_form(0)">
    	<input type="submit" class="fielder3" value="preview">
    </form>
    The action of the form is an ASP file, which edits the submitted string and then redirects back to the original page that contains the form. The redirection contains a value in the querystring. If I execute the form with the <input type="submit"> method, the page is redirected back to itself and the querystring is present. If the form is submitted via JavaScript, the ASP file still executes correctly but when it redirects back the querystring name value pair is not present (e.g., edit.asp?). I have no idea why this is happening. The stranger thing is that if I submit the form again, without the required info in the querystring, the ASP page still works. It's as if the querystring info is there even though it isn't visible in the address bar. Any thoughts on what is going on?

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <form name="submit_button" onsubmit="return submit_form(0)">
    	<input type="submit" class="fielder3" value="preview">
    </form>
    You are esentially submitting twice using the submit button and the submit() method. Try using only one of them.

    <input type="button" class="fielder3" value="preview" onclick="return submit_form(0)">

    With this one remove the onsubmit you have above.

    OR

    leave the button the same but remove the javascript submit. Is this all of your code because that just seems to be a redundancy.

    Otherwise I am not sure why it is doing what it is doing but you are esentially submitting the form twice with your current code
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maelstrom-

    Thanks for your help. I found a work-around that did the trick, but it's basically the same thing that you suggested. I have one form with lots of hidden elements that I submit from another location; that's why the code looked weird. I solved the problem by using the <input type="button"> tip just as you suggested.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •