0

I have built a large from and I have just discoverd my <button></buttom> does not work as a link

I am using

 <button onclick="window.location.href='myurl'">Next</button>

, but it is not working

Help.

5
Contributors
10
Replies
35
Views
4 Years
Discussion Span
Last Post by IIM
Featured Replies
  • 3

    You can still have one function called "clicky". Just pass the URL to the function as well... <html> <head> <script type="text/javascript"> function clicky(param){ location.href = param; } </script> </head> <body> <button onclick="clicky('http://www.daniweb.com');">Next</button> <button onclick="clicky('http://www.other.com');">Another Button..</button> </body> </html> Read More

0

Maybe I'm way off here but isn't the onclick event supposed to call a function? Maybe you have to include the link in a function and call it that way. Again, I may be way off but I'm just throwing my 2 pennies around right now.

0

You could be right, could you provide an example please

1

Sure, this should be close to what you need

<html>
    <head>
        <script type="text/javascript">
            function clicky(){
                location.href = 'http://www.daniweb.com';
            }
        </script>
    </head>
    <body>
        <button onclick="clicky();">Next</button>
    </body>
</html>
0

Cool, nice.

the only problem i have is that that there are 9 button on the main page that go to 9 different locations.

Do i do this 9 time?

thanks boss! :-)

0

My lack of experience with this issue says yes, create 9 functions calling them click1, click2,...,click9. However, there may be a better way to do that but I'm just not sure what it is. Maybe someone else will be able to jump in on this and let you know.

3

You can still have one function called "clicky". Just pass the URL to the function as well...

<html>
    <head>
        <script type="text/javascript">
            function clicky(param){
                location.href = param;
            }
        </script>
    </head>
    <body>
        <button onclick="clicky('http://www.daniweb.com');">Next</button>
        <button onclick="clicky('http://www.other.com');">Another Button..</button>
    </body>
</html>
Votes + Comments
Very cool, thanks for helping out and I learned something here too.
1

When you say your original code (<button onclick="window.location.href='myurl'">Next</button>)doesn't work, what exactly do you mean? I tried it in FireFox 22, Chrome 27 and Internet Explorer 10 and it worked fine.

0

yes zagga you are right. You can directly like directly like javascript in onclick event(if it is a single line ,without calling function.
I have been using <button onclick="window.location.href='myurl'">Next</button> since i was working on IE8,and still all browsers supports it.
For an example ,check this

<html>
<head><title>HREF</title></head>
<body>
<input type="button" onclick="window.location.href=('http://www.google.com')">
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.