0

Hi I´m new with javascript and I´m trying to learn everything I can and I came yesterday to this problem. I was trying to programe my own calculation, but this problem occured:

with this input, the script is working well: <input type="button" value = "1" onClick = "pridajZnak(kalkulacka, jedna)">

but with this, it´s kind of broken: <button name="jedna" onClick="pridajZnak(kalkulacka, jedna)">1</button>

The problem is that function pridajZnak is adding one char to the actual value of different element, input working well, but button is doing funny things, after button pressed it will just blick with added char and then come back to previous state...

Can someone tell me where´s the problem? I just want to undestand the difference...thanks

4 Answers4

2

try this type="button" like this

<button name="jedna" type="button" onClick="pridajZnak(kalkulacka, jedna);">1</button>

hope it will help

Sonu Sindhu
  • 1,752
  • 15
  • 25
0

Button tag has attribute value. Assign the value and I think it should be fine

0

try placing return false; on onclick event. Example:

<button name="jedna" onClick="pridajZnak(kalkulacka, jedna); return false;">1</button>
Siddhartha Gupta
  • 1,140
  • 8
  • 13
0

Does this solve your problem?

<input type="button" name="jedna" onClick="pridajZnak(kalkulacka, jedna)" value="1"></input>

Edit: Oh! I saw your part about wanting to understand the difference - commendable.

You're using an <input> for the text field and a <button> for the button. It is possible to use an <input> for both. There's some more information about input vs. button in this SO answer. Also, you've set the value as an attribute on the <input>, while you've set the value between the tags on the <button>. I'm fairly sure you can't do this with an <input>.

Good luck!

Community
  • 1
  • 1
David
  • 444
  • 2
  • 9