HTML form submission in Opera

The HTML form shown below does not work in Opera (version: 9.52). The form has no onsubmit attribute and no input element with type = submit. It just has two type = button input elements and both of them onclick call the js method where I want the user to confirm the view. If I remove the confirm () call it works fine. And in all other browsers (FF2, FF3, IE7) it works fine.

Any pointers?

<script type = "text/javascript">
function userSubmit(submitStatus)
{
    // Omitted code that uses the parameter 'submitStatus' for brevity
    if(confirm('Are you sure you want to submit?'))
        document.qpaper.pStatus.value = something;
    else
        return;     
    document.qpaper.submit();
}
</script>
<form  name = "qpaper" method = "post" action = "evaluate.page">
    <input name = "inp1" type = "button" value = "Do This" class = "formbutton" onClick = "userSubmit(false)">
    <input name = "inp2" type = "button" value = "Do That" class = "formbutton" onClick = "userSubmit(true)">
</form>

      

0


source to share


1 answer


  • Never use document.nameofsomething

    . This is a legacy technique that has mixed support in 21st century browsers. For forms use document.forms.nameofform

    .

  • Don't use onclick on buttons unless you need Javascript to behave differently depending on which button was clicked. If you just want to validate a form or confirm a submission, use instead <form onsubmit>

    .

    <form onsubmit="return confirm('Sure?')">
    
          

    And so you don't even need to form.submit()

    . If it <form onsubmit>

    returns false, the feed will be aborted.

  • You don't even need to find this form.
    In the form <button onclick>

    will be this.form

    .
    The form <form onsubmit>

    will be in a variable this

    .



+2


source







All Articles