0

So, when i click a button my jQuery dosent change the value of the div, this onaly happens in safari in all other browsers it works!

Javascript:

$(document).keypress(function(){
	if (event.keyCode==13) key('=');
	if (event.keyCode==42) key('*','x');
	if (event.keyCode==43) key('+','+');
	if (event.keyCode==45) key('-','-');
	if (event.keyCode==46) key('.');
	if (event.keyCode==47) key('/','÷');
	if (event.keyCode==48) key(0);
	if (event.keyCode==49) key(1);
	if (event.keyCode==50) key(2);
	if (event.keyCode==51) key(3);
	if (event.keyCode==52) key(4);
	if (event.keyCode==53) key(5);
	if (event.keyCode==54) key(6);
	if (event.keyCode==55) key(7);
	if (event.keyCode==56) key(8);
	if (event.keyCode==57) key(9);
});
function key(x,y){
	if (y){
		$('#temp').append(x);
		$('#screen').append(y);
	} else {
		if (x=='ac'){
			$('#screen').html(0);
			$('#temp').html('');
			$('#op').html('');
		} else {
			if (x=='='){
				$('#screen').html(eval($('#temp').html()));
			} else {
				$('#temp').append(x);
				if ($('#screen').html()==0){
					$('#screen').html(' ');
				};
				$('#screen').append(x)
			}
		}
	}
}

HTML:

<div id="temp"></div>
    <div class="screen">
      <div id="screen">0</div>
    </div>
    <div class="top">
      <button onclick="key('ac')" id="ac">AC</button>
      <br />
    </div>
    <div class="round">
      <button onclick="key(7)">7</button>
      <button onclick="key(8)">8</button>
      <button onclick="key(9)">9</button>
      <button onclick="key('/','&divide;');">&divide;</button>
      <br />
      <button onclick="key(4)">4</button>
      <button onclick="key(5)">5</button>
      <button onclick="key(6)">6</button>
      <button onclick="key('*','x');">x</button>
      <br />
      <button onclick="key(1)">1</button>
      <button onclick="key(2)">2</button>
      <button onclick="key(3)">3</button>
      <button onclick="key('-','-');">-</button>
      <br />
      <button onclick="key('.')">•</button>
      <button onclick="key(0)">0</button>
      <button onclick="key('=')">=</button>
      <button onclick="key('+','+');">+</button>
    </div>

Edited by aidant: n/a

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by twiss
0

What happens if you change

<button onclick="key(7)">7</button>

to

<input type="button" onclick="key(7)" value="7" />

, etcetera?

0

my css is just styling the button tag, so the rounded effect wont go on, dont really see how that would effect it though.

Edited by aidant: n/a

0

Yes, but you could use input[type=button] in your CSS, too. Another idea is to change onclick to onfocus.

0

Solved:

JavaScript was off as safari is my noscript testing browser, silly of me.

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.