SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking very very simple help in simple js code

    hi,


    i have js code , and i want edit it to add code

    this is the default js code :
    Code:
    <script type="text/javascript">
    function changeActiondeact1()
    	{  
    		var x=document.getElementById("myForm")
    		x.action="index.php?act=read"
    		x.submit()
    	}
    </script>
    the code is to change form action when i add others buttons width default submit button ,

    what i want to do is adding code to send confirm message to user with yes or no , if he choosed yes then submit the form , else if he choosed no , don't do any thing and don't submit the form


    i tried to eit it like this :
    Code:
    <script type="text/javascript">
    function changeActiondeact1()
    	{  
                             confirm("Are u Sure ?");
                             return false;
    		var x=document.getElementById("myForm")
    		x.action="index.php?act=read"
    		x.submit()
    	}
    </script>
    and it work with confirm message . but the problem is when choose yes or no button it run and form and submit it

    so can u give me true code ?

    thanks

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Look at the documentation for confirm. It returns true or false, which is what you use to know whether the user pressed OK or cancel.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    if (! confirm("Are u Sure ?")) return false;
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello Raffles , felgall

    thank u very much

    felgall

    i tried your solution , but also when choose "cancel" button it run the form action !

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    You need to return the result of the function back to the event itself.

    Code html4strict:
    <tag onclick="changeActiondeact1()"><!-- BAD -->
    <tag onclick="return changeActiondeact1()"><!-- GOOD -->
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    You need to return the result of the function back to the event itself.

    Code html4strict:
    <tag onclick="changeActiondeact1()"><!-- BAD -->
    <tag onclick="return changeActiondeact1()"><!-- GOOD -->
    hello pmw57
    thank u very very much .. it's working now


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
  •