Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onSubmitForm not working

    Hello, I have a simple JavaScript that for some reason doesnt work.
    The problem is when I push the delete image, I get the confirm if I want to delete or not, but when I push ok, I dont get forwarded to the action deleteCompany.jsp

    And I cant figure out why.

    Here is the code:

    Code:
    <c:forEach var="company" items="${companyList}">
    		<tr>
    	    <td width="30%"><a href="../index.jsp?action=search&companyId=<c:out value="${company.id}"/>&year=all"><c:out value="${company.name}"/></a></td>
    	    <td width="5%" align="center">
    	    	<form name="editCompanyForm" action="editCompany.jsp" method='POST'>
    			<input type="hidden" name="companyId" value="<c:out value="${company.id}"/>"/>
    	        <input type="hidden" name="returnpage" value="index.jsp"/>
    	        <input type="image" src="images/edit.png" border="0" alt="Rediger Selskap">
    	    </td>
    	        </form>
            <td width="5%" align="center">   	
               	<form onSubmit="return onSubmitForm();" name="removeForm" method="post">
    	        <input type="hidden" name="companyId" value="<c:out value="${company.id}"/>"/>
    	        <input type="hidden" name="returnpage" value="index.jsp"/>
    	        <input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onClick="document.pressed=this.value">
    	        </form>
    	        
    	    </td>
    	</tr>
    	</c:forEach>
    
    </body>
    
    <script type="text/javascript">
    <!--
    function onSubmitForm() {
    	if(document.pressed == "Lagre") {
    		document.editCompanyForm.action = "editCompany.jsp";
    	} else if(document.pressed == "Slett") {
    		var r=confirm("Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet")
    		if (r==true) {
    			document.removeForm.action = "deleteCompany.jsp";    
    	    } else {
    		    document.removeForm.action = "?";
    		}
    	} 
    	
    	return true;
    }
    -->
    </script>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What exactly is document.pressed? Explain to us what you think that should be.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You can do it this way:
    Code:
    <input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onclick="document.removeForm.action=(confirm('Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet'))?'deleteCompany.jsp':'?';" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Feb 2007
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    What exactly is document.pressed? Explain to us what you think that should be.
    What I want to happen is that it matches what form which has been submitet, and then I want a dialog box saying, are you sure you want to delete. And then when the user presses yes, I want it to go to the specified action. But it seems like it always just refreshes on the same page.

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    You can do it this way:
    Code:
    <input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onclick="document.removeForm.action=(confirm('Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet'))?'deleteCompany.jsp':'?';" />
    Alright thanks Glenn. I will try that when I get back to work tomorrow.


  •  

    Posting Permissions

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