admin管理员组文章数量:1332987
i tried to set up a onclick function on a "reset" button type, which will only work if i click it twice, i've even tried it as a normal button type with the same results. I've placed it on other parts of the site but the same results persists.
The functions it does is that it erases out text that appears dynamically everytime you add a new order. And the html reset functions wipes out the rest of the sites input, which is ok i guess.
Here you can visit the website and see for yourself:
.php
Here is a part of the code,
var tester;
var tester = function () {
document.form['reset'].onclick = function () {
contact_box_kurv.innerHTML = ("").replace (/,/g, '');
return false;
};
};
</script>
<h2><INPUT TYPE="RESET" name="reset" id="reset" VALUE="Tøm Handlekurv" onclick="tester()"></h2>
Note: To see the function work on the website you will need to add an order.
i tried to set up a onclick function on a "reset" button type, which will only work if i click it twice, i've even tried it as a normal button type with the same results. I've placed it on other parts of the site but the same results persists.
The functions it does is that it erases out text that appears dynamically everytime you add a new order. And the html reset functions wipes out the rest of the sites input, which is ok i guess.
Here you can visit the website and see for yourself:
http://www.premiere-produkter.no/pp/lagersalg/index.php
Here is a part of the code,
var tester;
var tester = function () {
document.form['reset'].onclick = function () {
contact_box_kurv.innerHTML = ("").replace (/,/g, '');
return false;
};
};
</script>
<h2><INPUT TYPE="RESET" name="reset" id="reset" VALUE="Tøm Handlekurv" onclick="tester()"></h2>
Note: To see the function work on the website you will need to add an order.
Share edited Jan 24, 2013 at 8:10 Tepken Vannkorn 9,72314 gold badges62 silver badges86 bronze badges asked Jan 24, 2013 at 8:06 TommyTommy 833 silver badges10 bronze badges 3- Simply because you are using onclick twice.. – Shurmajee Commented Jan 24, 2013 at 8:10
- Removing mas from an empty string? – Musa Commented Jan 24, 2013 at 8:11
- @Musa - Better safe than, sorry. You, never know, where mas, are going to spring, up. ,,, – nnnnnn Commented Jan 24, 2013 at 8:12
2 Answers
Reset to default 4Your button has an inline onclick
attribute that calls tester()
. So on first click it'll do whatever tester()
does - which is replace that with another onclick
set to the anonymous function inside tester()
. So then on second click it'll do what that second anonymous function does.
Try this instead:
var tester = function () {
contact_box_kurv.innerHTML = ("").replace (/,/g, '');
return false;
};
(I.e., have the desired functionality directly in tester()
.)
You need to put this script separately:
window.onload = function ()
{
document.form['reset'].onclick = function () {
contact_box_kurv.innerHTML = ("").replace (/,/g, '');
return false;
};
};
Remove the event handler script.
本文标签: javascriptonclick function not working at first clickStack Overflow
版权声明:本文标题:javascript - onclick function not working at first click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262322a2442745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论