Web Analytics Made Easy -
StatCounter onclick confirm then window.location - CodingForum

Announcement

Collapse
No announcement yet.

onclick confirm then window.location

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • onclick confirm then window.location

    how can you do

    onclick="return getconfirm('do you want to logout?');"
    onClick="window.location('logout.asp');"

    on the same button , if confirm then go url else stay here ?

    thank you

  • #2
    I'm not sure what getConfirm is, but this is the way I would do it:
    Code:
    onclick="if(confirm('do you want to logout?')) window.location('logout.asp');"
    Hope that helps,
    Sadiq.

    Comment


    • #3
      not work

      it doesn't work

      <a href="" onclick="if(confirm('do you want to go?')) window.location('logout.htm');">go</a>

      or

      <input type="button" value="go" onclick="if(confirm('do you want to go?')) window.location('logout.htm');"/>

      thank you for helping

      Comment


      • #4
        Whoops, I wasn't paying attention to the syntax! Just copying and pasting....

        This one should do it then:
        Code:
        <input type="button" value="go" onclick="if(confirm('do you want to go?')) window.location.href='logout.htm';"/>
        location isn't a method, so that didn't make sense.

        Hope that works!
        Sadiq.

        Comment


        • #5
          Just to confirm, what wasn't working?

          Was the confirm box showing up, but it just wasn't taking you to the right page? In that case, my post should fix that.

          If the confirm box wasn't even showing up, then we've got a different problem (not sure what it is though....).

          Sadiq.

          Comment


          • #6
            yes the box is shown ... but if I click yes I get an error

            thx !

            Comment


            • #7
              It does not

              function goConfirm(title,link)
              {
              if (confirm(title)==true)
              return true;
              window.location=link;
              else
              return false;
              }


              <input type='button' value='go' onclick="goConfirm('Do you want to go ?','index.htm');" />

              this code does not work .. why ?

              thank you

              Comment


              • #8
                You are exiting the function before you actually change the location. Try this:

                Code:
                function goConfirm(title,link) {
                	if(confirm(title)) {
                		window.location = link;
                		return true;
                	}
                	return false;
                }
                Hope that helps!

                Happy coding!

                Comment


                • #9
                  try adding some braces, also, you may have your return statement too soon.

                  Code:
                  <script type="text/javascript">
                  function goConfirm(title, link){
                     if(confirm(title) == true){
                        window.location.href = link;
                        return true;
                     } else {
                        return false;
                     }
                  }
                  </script>
                  
                  
                  <input type='button' value='go' onclick="goConfirm('Do you want to go ?','index.htm');" />
                  Hope this works for you.
                  PHP Weekly - A PHP Developers Resource
                  PHP 5.1.4 and Ruby on Rails web hosting
                  Moderator of PHP and Work offers and Requests
                  Install Apache/PHP/MySQL
                  (by marek_mar) | TinyPlugin Architecture

                  Comment


                  • #10
                    I was not very far :-))

                    it works now .. thank you

                    Comment


                    • #11
                      alert when link is onclick

                      Hi coders!

                      I was looking in the forum for a way to ask if the user really want to fallow the link that they are clicking on. But Im using extern file to du my funktion and want to separate HTML from my javaScript. I got inspirated with your suggestions and made this:

                      Code:
                      function init(){
                      
                      document.getElementById("capoeira").onclick = "linkConfirm(Vill du fِlja lنnken?);"
                      
                      function linkConfirm() {
                      
                      	if (confirm(capoeira) == true){
                      		window.location.href = link;
                      		return true;
                      		}
                      			else {
                      				return false;
                      				}
                      				}
                      
                      }
                      window.onload = init;
                      The link in my HTML:
                      Code:
                      <a href="http://www.capoeiras.se" name="capoeira">Se hemsidan</a>
                      What have I missed? And how can I make the code so I can put the same action when I add more links? Make an array?

                      Comment

                      Working...
                      X