Log in

View Full Version : Button not working



jelly46
07-05-2013, 03:07 PM
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.

coothead
07-05-2013, 03:38 PM
Hi there jelly46,

can you supply a link to the site in question or the the full
code so that members may better assess your problem?

coothead

jelly46
07-05-2013, 03:40 PM
Hello, its not live yet, i haven't uploaded any thing.

What you see is the problem i have.

Sorry, but thanks for replying.

coothead
07-05-2013, 03:47 PM
Hi there jelly46,

unfortunately, the snippet of code that you have supplied is insufficient to solve your problem.

That is why I requested the full code in the absence of a link. ;)

coothead

jelly46
07-05-2013, 03:51 PM
OK that's fair enough, can i explain a bit more I am building a page with 9 buttons on it. Each button goes to a different link.

How can i make <button></button> a link?

coothead
07-05-2013, 04:01 PM
Hi there jelly46,

you've already made the button a link. :)

To answer your question as to why it does not work, requires the the full code. ;)

By full code, I mean at least the code that includes a reference to the variable - "myurl".

coothead

janu
07-05-2013, 04:04 PM
try this


<form><input type="button" value="Next" onClick="window.location.href='myurl'"></form>

jelly46
07-05-2013, 04:05 PM
I don't have a url yet please use anyone you want.


<button onclick="window.location.href='http://www.google.com'">Next</button>

jelly46
07-05-2013, 04:06 PM
thanks janu, but it didn't work.

jelly46
07-05-2013, 04:09 PM
I'm using <button></button>, its all styled and ready to go.

janu
07-05-2013, 04:10 PM
have a look on screenshot .. I don't why it is not working for you

http://img5.imageshack.us/img5/5765/mzec.jpg

coothead
07-05-2013, 04:15 PM
Hi there jelly46,

Try it like this...


<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>untitled document</title>

<style>
.hide {
display:none;
}
</style>

<script>
(function() {
'use strict';

function init(){

var myurl='http://www.google.com';

document.getElementById('nxt').className='';
document.getElementById('nxt').onclick=function() {
location.href=myurl;
}
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
})();
</script>

</head>
<body>

<button id="nxt" class="hide">Next</button>

</body>
</html>

coothead

coothead
07-05-2013, 04:19 PM
Hi there jelly46,

by the way, your code...


<button onclick="window.location.href='http://www.google.com'">Next</button>
...does work. ;)

coothead