Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Javascript confirm

    hi everyone, i have a php page that was built for me to post some things to a mysql database, i wanted to add a confirmation to it, so heres what i have...

    Code:
    <head>
    <script language="JavaScript">
    function confirmation() {
    var answer = confirm("Are you sure you want to enter "+form1.Name.value+" as a new customer?")
    if (answer){
    SUBMIT FORM??
    }
    else{
    
    }
    }
    </script>
    </head>
    that part is working, but no matter what i have done, the form always gets submitted, im starting to think that i cant do this in java....can someone give me a hand here.....thanks.

    heres the php for the form:

    Code:
    <form action="<?php echo $editFormAction; ?>" method="POST"  onSubmit="confirmation()"name="form1">
    and the submit button:

    Code:
     <input name="submit" type="submit" id="submit" onclick=document.form1.action='<?php echo $editFormAction; ?>' value="Submit">
    Again thanks to any who help me.

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try
    Code:
    if (confirm("Are you sure you want to enter "+form1.Name.value+" as a new customer?")){form1.submit(); };
    The first time you had it right except for if (answer). That does nothing, and so would submit everytime. If you had if(answer==true), then it would have worked. The method I provided just shortens process and elimanates the need to create a local variable.
    Last edited by Burgerking63; 07-11-2005 at 10:42 PM.

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ok made the modification and its still submitting the form....heres what i have now:

    Code:
    <script language="JavaScript">
    function confirmation() {
    if (confirm("Are you sure you want to enter "+form1.Name.value+" as a new customer?")){form1.submit(); };
    }
    </script>
    thanks for your help.
    Last edited by pita0017; 07-11-2005 at 11:11 PM.

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try
    Code:
    if (confirm('Are you sure you want to enter '+form1.Name.value+' as a new customer?')){form1.submit(); }

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    still submits when i hit cancel or "x"...

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your forcing the form to submit twice by calling a PHP function to submit for the Submit button's onClick event, as well as a OnSubmit event handler for the form. Remove the Onclick event handler from the Submit button and let it do its job, the form's OnSubmit event handler will call the function before it submits. You just doubling the process, if this doesnt work, there is one more thing to try, but I am thinking it is your code that is flawed
    Last edited by Burgerking63; 07-11-2005 at 11:53 PM.

  • #7
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ok, did that and same deal, this is quite frustrating, as im sure its becoming for you...

    so now i have submit button:

    Code:
    <input name="submit" type="submit" id="submit" onclick="confirmation();" value="Submit">
    and form:

    Code:
    <form action="<?php echo $editFormAction; ?>" method="POST" name="form1">
    thanks for the help, its greatly appreciated.
    Last edited by pita0017; 07-11-2005 at 11:55 PM.

  • #8
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I edited my post just as you replied, check my previous post

  • #9
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Burgerking63
    I edited my post just as you replied, check my previous post
    me too..lol

  • #10
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You must have misread my edited post since you still have a "onclick=confirmation();" in your submit button code. This will not work as it will submit after you click because of the properties of the "submit" type of input. Re-read my post and make sure you follow the instructions then let me know if it works

  • #11
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sorry, i did misread it, im understading to leave the submit button alone, and to call the function from the forms OnSubmit event....so i did that and now have this, which still is not working, let me know, thanks.

    Code:
    <form action="<?php echo $editFormAction; ?>" method="POST" onSubmit="confirmation();" name="form1">
    Code:
    <input name="submit" type="submit" id="submit" value="Submit">

  • #12
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    alright, it looks like your going to have to use a return method that is dependant on a set of parameters. Since I'm assuming your not doing any form validation at this point, I'm just posting a confirmation to submit or cancel when the users clicks the submit button. Here is your script code:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function confirmation(f){
    if (confirm('Are you sure you want to enter '+form1.Name.value+' as a new customer? Click "OK" to submit change or "CANCEL" to reject the change')) {
    f.submit();}
    else {
    return false }
    }
    </script>
    Here is your form code:
    Code:
    <form action="<?php echo $editFormAction; ?>" method="POST" onSubmit="return confirmation(this)" name="form1">
    BTW, your submit button code is now fine, as long as it does not contain any event handlers.

  • #13
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    wow, thats a beautiful thing...lol....thank you.

    now if i did want to add form validation, im assuming i cant have 2 onSubmit events? or could i add it to the submit button's onClick event?
    Last edited by pita0017; 07-12-2005 at 12:41 AM.

  • #14
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can have as many functions called during"onsubmit" as you want. You would just seperate each time you call a function with a ";", for example:
    Code:
    onSubmit="function1(); function2()"
    As long as you call the function that would submit the form last, the others will run first. If you choose to go this route, my suggestion would be to have each function sequentially call the next eliminating the need for multiple properties in your OnSubmit event handler. For example:
    Code:
    <script>
    function1(){ alert('dododo'); function2(); }
    </script>
    <script>
    function2(){
    do this;
    then that;
    submitForm();}
    </script>
    <script>
    submitForm(){
    form1.submit(); }
    </script>
    Then your onSubmit would be this:
    Code:
    onSubmit="function1();"

  • #15
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    excellent, when i get the form validation code written up and tested i will then integrate it with the confirmation code and test, if i have any problems i will let you know....thank you once again, you are very knowledgeable and helpful.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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