Jump to content

Problem with form submit


Johns3n

Recommended Posts

Hello Folks! :)

 

I was hoping that you could help me with a problem, regarding a form submission through JavaScript? The script it self does everything I want it to up to the part where it is suppose to submit the form.

 

Here is the form with form id, form action and eveything needed to process a good form:

<form name='select_comments' id='selected_comments' action='deletecomment.php?action=selected' method='post'>
<input name='submit' type='button' value='Delete selected' onclick='javascript:confirmation_selected_comments()'/>

 

Inside the form there are a few check boxes which I set up as being posted as a array of data, here is the code for the checkboxes:

<input name='itemids[]' type='checkbox' value='" .$row['id']. "' />

 

If i remove all JavaScript and handle the form as a normal form would be handled, it processes all the data 100% correct, however I tried to implement a "confirmation box" that appears before you submit the form, just to verify if the user "really wan't to do this?"

 

The script for the confirmation box I have written like this:

    <script type="text/javascript">
    function confirmation_selected_comments() {
    var warning = confirm("Are you sure you want to delete selected entries?" + '\n' + '\n' + "This can NOT be undone!")
	if (warning)
	{
	document.selected_comments.submit();
	}
	else
	{
	}
}
    </script>

 

Now the code used like this works up until it actually submits the form, it shows the confirmation box and askes, do you really want to do this? But when I click "ok" it does not submit the form to the action=' ' page, stated in the form.

 

I did write the correct ID for the form in the document.submit string, but it's still not submitting the form, so I am hoping that you can maybe point in the right direction where I am going wrong? :)

 

Thanks in Advance

- Kenneth

Link to comment
Share on other sites

document.selected_comments.submit(); <-- this is calling the 'name' no the 'id', calling the id would be document.getElementById('selected_comments').submit();

 

you have your form name select_comments and the id selected_comments.  show that line above should be document.select_comments.submit() instead, or the form name should be selected_comments, instead of select_comments

Link to comment
Share on other sites

document.selected_comments.submit(); <-- this is calling the 'name' no the 'id', calling the id would be document.getElementById('selected_comments').submit();

 

you have your form name select_comments and the id selected_comments.  show that line above should be document.select_comments.submit() instead, or the form name should be selected_comments, instead of select_comments

 

Ahhh from what I read, it took the ID and not the name! But I tried switching it around so it looked like this:

 

Form:

<form id='select_comments' action='deletecomment.php?action=selected' method='post'>
<input name='submit' type='button' value='Delete selected' onclick='javascript:confirmation_selected_comments()'/>

Form submit script:

    <script type="text/javascript">
    function confirmation_selected_comments() {
    var warning = confirm("Are you sure you want to delete selected entries?" + '\n' + '\n' + "This can NOT be undone!")
	if (warning)
	{
	document.getElementById('select_comments').submit();
	}
	else
	{
	}
}
    </script>

 

Unfortunaly it's not working still :(

Link to comment
Share on other sites

name and id should be the same in your form tag.  javascript can be picky at times and I have found this to solve a lot of annoying bugs.

 

so give document.select_comments.submit() a shot (assuming that's the name you went with rather than trying to submit with the ID element.

 

Link to comment
Share on other sites

name and id should be the same in your form tag.  javascript can be picky at times and I have found this to solve a lot of annoying bugs.

 

so give document.select_comments.submit() a shot (assuming that's the name you went with rather than trying to submit with the ID element.

 

Tried what you said! And it's still not working! I'll post the changes I made:

 

<form id='select_comments' name='select_comments' action='deletecomment.php?action=selected' method='post'>
<input name='submit' type='button' value='Delete selected' onclick='javascript:confirmation_selected_comments()'/>

 

<script type="text/javascript">
    function confirmation_selected_comments() {
    var warning = confirm("Are you sure you want to delete selected entries?" + '\n' + '\n' + "This can NOT be undone!")
	if (warning)
	{
		document.select_comments.submit()
	}
	else
	{
	}
}
    </script>

 

Please note that I have placed the javascript outside the <form> tags but it should still work no?

Also the stuff inside the <form> tags are posted within echo's that i close and open, close and open and close with the </form> but should still work regardless!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.