www.webdeveloper.com
Results 1 to 7 of 7

Thread: two onclick event for a single button

  1. #1
    Join Date
    Nov 2008
    Posts
    4

    Question two onclick event for a single button

    Hi,
    I'm new to Jscript,here's my Requirement i have some 10 fields in my page(validation is working fine) and a form to submit this,the problem arises when a user disables the Jscript,so i thought of putting a Jscript Form submit like this

    function submit_form()
    {
    document.myform.submit();
    }

    But i've already got a on click button action in my page,so my problem is if the user disable Jscript, he can't submit the form .How can i do this

    Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    1,666
    The standard solution is to provide a standard HTML <input type=submit> button and fire your JavaScript validation from the FORM tag's onsubmit event -- not from a non-standard button's onclick event. You can still return false to the onsubmit event to prevent the form from being submitted -- and return true when you want the form to go ahead and submit. This way, if JavaScript is disabled, then the form can still be submitted and you just use your server-side validation code to do what the JavaScript validation code could not do.
    HTML Code:
    <form ... onsubmit="return ValidateForm(this)">

  3. #3
    Join Date
    Nov 2008
    Posts
    4
    Quote Originally Posted by MrNobody View Post
    <input type=submit> button and fire your JavaScript validation from the FORM tag's onsubmit event -- not from a non-standard button's onclick event
    .

    I think i've to be more specific.

    This way, if JavaScript is disabled, then the form can still be submitted and you just use your server-side validation code to do what the JavaScript validation code could not do.
    HTML Code:
    <form ... onsubmit="return ValidateForm(this)">
    My Requirement is this Don't submit the Form if Jscript is disabled,only allow submitting the Form only when Jscript is enabled ,so i think i may be wrong to have <input type=submit> and onemore thing i already have a onclickevent for my clientside validation,so pls advise me on this

    Thanks

  4. #4
    Join Date
    Feb 2008
    Posts
    1,666
    So you say you don't want the user to be able to submit the form if JavaScript is disabled. So show your HTML for the button you have. I'm not a mind reader.

  5. #5
    Join Date
    Nov 2008
    Posts
    4
    Code:
    <input name="Submit" type="submit" class="bodyText" id="buttonsubmit" onclick="return formValidator();" value="Register Now" />
    The onclick event is for my field validation & it works fine,and i know the Form is submitting even though the script is disabled because of the fact of TYPE="Submit",but i don't want this to happen,so i want something like the FORM to be submitted on Jscript so if user disables it no action performed, i think this will give a clear idea

    Thanks

  6. #6
    Join Date
    Feb 2008
    Posts
    1,666
    OK, just change that to a non-submitting button:
    Code:
    <input type="button" name="Submit" class="bodyText" id="buttonsubmit"
     onclick="return formValidator();" value="Register Now" />
    However, be aware that some browsers will submit the FORM when the ENTER key is pressed in a text field. Without JavaScript, there is no to prevent this behavior.

  7. #7
    Join Date
    Nov 2008
    Posts
    4

    Thumbs up

    Thanks Thanks Guys I've Got it

    Meet you with others Issues Guys

Thread Information

Users Browsing this Thread

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

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