Jump to content

Submit a form using JS


emvy03

Recommended Posts

Hi,

I'm having trouble submitting a form using javascript. I have 2 javascript submit buttons (One uploads a story to the site and the other if for a search function) on my site, and another submit button assigned to 'story' that a user uploads. The problem I am having is with this last submit button. I'm using the same script as with the other two buttons and the submit function works in that the page reloads, nothing happens with regards submitting any code.

I'm confident that the form works because there is no issue when using a standard issue submit button.

 

The form code:

<form name='voteForm' id='voteForm' action='vote2.php' method='POST'>
<a href='javascript: submitvote()' id='submit'><img id='green' src='images/greenbtn.png' alt='' ></a>
<input type='hidden' id='pid1' name='pid1' value='$id' >
<input type='hidden' id='page' name='page' value='$page' >
<input type='hidden' id='title' name='title' value='$rumourID'>
</form>"

 

The Javascript:

<script type="text/javascript">
function submitvote()
{
if(document.searchForm.onsubmit &&
    !document.searchForm.onsubmit())
    {
        return;
    }
document.searchForm.submit();
}
</script>

 

Thanks for reading guys!

Link to comment
Share on other sites

function submitvote()
{
    if(document.voteForm.onsubmit &&
    !document.voteForm.onsubmit())
    {
        return;
    }
document.voteForm.submit();
}
</script>

 

I'm using the exact same code for an upload form as well and that works with out any problems.

Link to comment
Share on other sites

A named submit button's value won't be submitted unless you actually click it. What does the PHP code look like? If "vote2.php" only handles one form, then just check if any POST data was submitted to detect the submission:

 

if (!empty($_POST)) {

 

If it handles multiple forms, check if one of the required fields is not empty like above.

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.