admin管理员组文章数量:1434924
I am using an onsubmit variable to ensure that the user really means to delete something, however as soon as I put a value in the parenthesis inside the onsubmit it no longer calls the confirm box.
Code:
onClick="confirmSubmit(abc)"
Doesn't work but the following:
onClick="confirmSubmit()"
Does work
Function:
function confirmSubmit(category)
{
var category = category;
var agree=confirm("Are you sure you wish to DELETE" + category + " and all of its subcategories and photos?");
if (agree)
return true ;
else
return false ;
}
I am using an onsubmit variable to ensure that the user really means to delete something, however as soon as I put a value in the parenthesis inside the onsubmit it no longer calls the confirm box.
Code:
onClick="confirmSubmit(abc)"
Doesn't work but the following:
onClick="confirmSubmit()"
Does work
Function:
function confirmSubmit(category)
{
var category = category;
var agree=confirm("Are you sure you wish to DELETE" + category + " and all of its subcategories and photos?");
if (agree)
return true ;
else
return false ;
}
Share
Improve this question
asked Jul 20, 2011 at 18:55
George ReithGeorge Reith
13.5k18 gold badges82 silver badges151 bronze badges
1
-
confirm()
returns a boolean, so you can shorten your return statement by just returning the return value of the confirm.return confirm("Are you sure...");
. – user113716 Commented Jul 20, 2011 at 19:00
4 Answers
Reset to default 5you need quotes around your abc
:
onclick="confirmSubmit('abc')"
Without them you are trying to pass a variable, abc
, which doesn't exist and triggers an error
onClick="confirmSubmit(abc)"
is trying to pass the variable abc
, if you intend to pass a string with the value "abc" then do this:
onClick="confirmSubmit('abc')"
function confirmSubmit(category)
{ var category = category;
And you've declared "category" twice! Once in the function header and then as a function variable in the next line! What for?
You're try to pass the variable abc
(which does not exist) to the function.
Do:
onclick="return confirmSubmit('abc');"
本文标签: Javascript Passing variable to function breaks functionStack Overflow
版权声明:本文标题:Javascript: Passing variable to function breaks function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745644200a2668037.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论