admin管理员组文章数量:1389157
(I've changed the input tag with a button tag.) This probably is a stupid question, but here goes. I have an input button like this:
<button type="submit"
id="choice"
value="Escolher"
onClick="javascript:makeChanges()">
It works well in IE, but in firefox it just doesn't do anything; there are no errors, no behavior what so ever.
My "makeChanges()" function does the following:
var selObj = document.getElementById('opiniao');
var selIndex = selObj.selectedIndex;
var str = selObj.options[selIndex].text +'&random='+(new Date()).getTime();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","writeSettings2.php?text="+str,true);
xmlhttp.send(null);
history.go(0);
}
If i put for isntance an alert on the call like:
<button type="submit"
id="choice"
value="Escolher"
onClick="alert('Hello')">
The button works, but it dosent when i try to call the javascript function.
(I've changed the input tag with a button tag.) This probably is a stupid question, but here goes. I have an input button like this:
<button type="submit"
id="choice"
value="Escolher"
onClick="javascript:makeChanges()">
It works well in IE, but in firefox it just doesn't do anything; there are no errors, no behavior what so ever.
My "makeChanges()" function does the following:
var selObj = document.getElementById('opiniao');
var selIndex = selObj.selectedIndex;
var str = selObj.options[selIndex].text +'&random='+(new Date()).getTime();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","writeSettings2.php?text="+str,true);
xmlhttp.send(null);
history.go(0);
}
If i put for isntance an alert on the call like:
<button type="submit"
id="choice"
value="Escolher"
onClick="alert('Hello')">
The button works, but it dosent when i try to call the javascript function.
Share Improve this question edited Feb 3, 2011 at 15:21 Catarrunas asked Feb 3, 2011 at 14:38 CatarrunasCatarrunas 433 silver badges8 bronze badges 4- Look in the Firebug console for any JS errors, if it's not working there should be some feedback as to why. – David Thomas Commented Feb 3, 2011 at 14:39
- 1 Have you tried ditching the "javascript:" in your onclick attribute? There's no need to specify that you're putting a script element in there. – Surreal Dreams Commented Feb 3, 2011 at 14:42
- 1 the input is of type submit. without a form, firefox doesnt know what to submit. – Victor Commented Feb 3, 2011 at 14:42
- @Victor: Your ment reads like an answer. Consider posting it. – Jeff Yates Commented Feb 3, 2011 at 14:43
7 Answers
Reset to default 2<input type="submit" />
is for submitting form data. Without <form>
firefox doesn't know where or how the form should be submitted, so it doesn't submit.
If you want to use a button without a form, you can use the <button>
tag.
try:
<input type="button" id="choice" value="Escolher" onClick="makeChanges()" />
what is your javascript? maybe there is a mistake?
Can you add some context about your code around this input element? Is it in a form (doesn't sound like it)? The "submit" input type needs to be in a form...can you just change it to a button input element instead?
<input type="button" id="choice" value="Escolher" onClick="javascript:makeChanges()">
The input is of type submit. Which indicates to submit a form. Without a form, Firefox doesnt know what to submit.
I just tried your code and it worked ok in Firefox 3. On the following HTML. Check if your function is defined. Or maybe it is your Firefox version?
<html>
<head>
<script type="text/javascript">
function makeChanges(){
alert('hi');
}
</script>
</head>
<body>
<input type="submit"
id="choice"
value="Escolher"
onClick="javascript:makeChanges()">
</body>
</html>
indeed this doesnt work on firefox (but works on IE, Chrome):
input type="button" value="Show Results" onClick="javascript:show()"
the solution is just put the javascript code inside the onClick
, for instance:
input type="button" value="Show Results" onclick="document.getElementById('dsp').value=1;sertificatesStatsForm.submit();"
If you have the type as "submit", browsers will attempt to post data to the enclosing <form> element's "action" attribute. You can disable this by adding "return false;" to your onclick handler. As others have said, "button" is the more appropriate type to use in this case. The below bare-bones example works for me:
<input type="button" onClick="javascript:alert('hello');" />
Do you perhaps have NoScript installed in Firefox? Normally, file:// is not allowed to execute JavaScript code.
本文标签: javascriptInput button in firefox doesn39t workStack Overflow
版权声明:本文标题:javascript - Input button in firefox doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744646112a2617408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论