www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript submitting wrong form

  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Unhappy Javascript submitting wrong form

    Hi,
    I not sure if I identified the problem correctly. I'm using Javascript to submit forms in a HTML file. In this particular case I have three of them all with different target urls.
    Yet, when I run the function submitting one form another form is submitted. When I have an alert just before the submit command it submits the correct one...
    Here's the code (or at least the relevant parts of it) so you'll better understand.
    First the html part:
    Code:
    <form method="post" action="refer_to_repair_activity.php" name="existing_repair_activity_form" id="existing_repair_activity_form">
    			<input type="hidden" id="existing_repair_activity_id" name="id" value="">
    			<input type="hidden" id="existing_repair_activity_cid" name="cid" value="">
    		</form>
    		
    		<form method="post" action="general_car_details.php" name="general_car_details_form" id="general_car_details_form">
    			<input type="hidden" id="general_car_details_id" name="id" value="">
    		</form>
    		
    		<form method="post" action="refer_to_repair_activity.php" name="add_new_repair_activity_form" id="add_new_repair_activity_form">
    			<input type="hidden" id="add_new_repair_activity_id" name="id" value="">
    		</form>
    And here's the Javascript function:
    Code:
    function submitExistingRepairActivity(rpID, carID)   {
    	document.getElementById("existing_repair_activity_id").value = rpID;
    	document.getElementById("existing_repair_activity_cid").value = carID;
    //      alert('some annoying alert');
    	document.forms[0].submit();
    }
    The function will be called when a link is clicked which will then provide the required parameters.

    The form submitted is always general_car_details_form.

    I would be happy for some ideas as to why this happens, especially because an alert just before submitting the form helps, setting breakpoints in the javascript debug mode helps as well, even though this is not really an option

  2. #2
    Join Date
    Jun 2012
    Posts
    2

    resolved

    OK, it might have been something different, I think the link which I wanted to use to call the submit function was not working as intended.
    I have the entire table row with an onclick-event calling one function and a link in that row calling another one.
    I removed the onclick-Event from the link-cell. Now it works. Hope that was understandable

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    voo-doo magic

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles