admin管理员组文章数量:1356318
I have a dropdown box with an onchange event. When I select a value in the dropdown I invoke a JavaScript function that accepts a few parameters then submits values to my controller. Here's what I have for the dropdown box:
<td><select class="input-medium" name="status" id="status" onchange="javascript:changeStatus(this.value, ${module.id}, ${module.status});">
<option <c:if test='${module.status == "Active"}'>selected="selected"</c:if> value="active">Active</option>
<option <c:if test='${module.status == "Inactive"}'>selected="selected"</c:if> value="inactive">Inactive</option>
<option <c:if test='${module.status == "Retired"}'>selected="selected"</c:if> value="retired">Retired</option>
</select></td>
Here's my JavaScript function:
<script type="text/javascript">
function changeStatus(dropboxStat, modID, curStat) {
alert (dropboxStat);
if (curStat.toString == "Active" && dropboxStat == "inactive")
alert ("This will delete all of the module's training entries that have not been pleted!");
document.updateForm.status.value = dropboxStat;
document.updateForm.modID.value = modID;
document.updateForm.submit();
}
</script>
When I change a row that had a status of "active" to "inactive", the if statement should be read as true and the alert should pop up. Right now I'm not even getting the first alert to pop up. Instead, I get this error:
ReferenceError: Active is not defined
I've read online about variables not being defined but this is just a String value...in which I thought wouldn't need to be defined. Any ideas and explanations as to why this error would get thrown?
I have a dropdown box with an onchange event. When I select a value in the dropdown I invoke a JavaScript function that accepts a few parameters then submits values to my controller. Here's what I have for the dropdown box:
<td><select class="input-medium" name="status" id="status" onchange="javascript:changeStatus(this.value, ${module.id}, ${module.status});">
<option <c:if test='${module.status == "Active"}'>selected="selected"</c:if> value="active">Active</option>
<option <c:if test='${module.status == "Inactive"}'>selected="selected"</c:if> value="inactive">Inactive</option>
<option <c:if test='${module.status == "Retired"}'>selected="selected"</c:if> value="retired">Retired</option>
</select></td>
Here's my JavaScript function:
<script type="text/javascript">
function changeStatus(dropboxStat, modID, curStat) {
alert (dropboxStat);
if (curStat.toString == "Active" && dropboxStat == "inactive")
alert ("This will delete all of the module's training entries that have not been pleted!");
document.updateForm.status.value = dropboxStat;
document.updateForm.modID.value = modID;
document.updateForm.submit();
}
</script>
When I change a row that had a status of "active" to "inactive", the if statement should be read as true and the alert should pop up. Right now I'm not even getting the first alert to pop up. Instead, I get this error:
ReferenceError: Active is not defined
I've read online about variables not being defined but this is just a String value...in which I thought wouldn't need to be defined. Any ideas and explanations as to why this error would get thrown?
Share Improve this question asked Feb 11, 2015 at 14:47 user1750824user1750824 1-
2
curStat.toString == "Active"
pares a function to a string. You probably meant to writecurStat.toString() == "Active"
– blgt Commented Feb 11, 2015 at 14:54
1 Answer
Reset to default 6Your onchange is being rendered as
changeStatus(this.value, 123, Active)
so it is seeing Active
as a variable and not a string. Hence the error.
You need to add the missing quotes around your arguments
<td><select class="input-medium" name="status" id="status" onchange="javascript:changeStatus(this.value, '${module.id}', '${module.status}');">
本文标签: htmlString is not defined in JavaScript functionStack Overflow
版权声明:本文标题:html - String is not defined in JavaScript function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744036124a2579801.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论