SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    5
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS not working in php

    Hi guys,

    I tried to use this code in html file and it is working fine but when i use the same code in php file (with get method/value after the file name . eg : file.php?id=1) the JS doesnt work anymore.. it still will direct to the next page eventhough the user click cancel.

    My code for ur reference :

    Code:
    function confirmation() 
    {
    var answer = confirm("Lets confirm!")
    if (answer==true)
    {
    	alert("Proceed"); // code will be inserted to redirect user to next page
    }
    else
    {
    		alert("I am not done");
    }
    }
    </script>
    
    
    <input type="image" onclick="confirmation()" value="Lets confirm" src="images/myimage.gif" alt="<? echo $useme ?>" name="personal" />
    Can somebody please let me know what I have done wrong and why the cancel button doesnt return back to the original page my php file? All I want is after the user click cancel, it will remove the alert box and display back to current page without directing the user to other page.

    Please assist. Thank you.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code never worked.

    All that code does is display alert messages.
    It does nothing to stop the form submission.


    Code:
    <form action="nextpage.php" onSubmit="return confirm('All Done?')">

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    I don't see in your code anything that would cause it to proceed to submit the form.
    What code do you have that's doing that? I ask this because that seems to be the problem that you're wanting to solve.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Member
    Join Date
    Sep 2006
    Location
    Columbia, MO
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    That code never worked.

    All that code does is display alert messages.
    It does nothing to stop the form submission.


    Code:
    <form action="nextpage.php" onSubmit="return confirm('All Done?')">
    Agreed. I'm not sure if I understand your example code, Ronan, but you should be using confirm() instead of alert() if you want the OK/Cancel functionality.
    Garvin

    Smooth Operator
    Snappy Dresser


Bookmarks

Posting Permissions

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