I'm coming across an odd issue, I've had this web application running for a few years now and only since people started using IE9 they get the below error. Has been working fine in IE6, 7 & 8.
'submit' is undefined
The code being used is this:
<a name="SaveButton" id="SaveButton" onclick="javascript:document.getElementById('action').value='validate'; submit();" href="#" >Save</a>
Any suggestions or help is greatly appreciated.
Update:
When I change it to this it seems to work find in IE9.
<a name="SaveButton" id="SaveButton" onclick="javascript:document.getElementById('action').value='validate'; formname.submit();" href="#" >Save</a>
*formname is the name of the form being submitted.
submit function in JavaScript is valid for form element. So this code is invalid , and only somehow works in older internet explorer.
For buttons or inputs the correct syntax is this.form.submit()
The cause of the problem was due to IE9 not liking the submit() function call coming from an A HREF tag, it should really be used in an INPUT or BUTTON tag.
The way around this due to not being able to modify the majority of the codebase was to add in the form name just before the submit function call like below:
formname.submit();
Final, working code:
<a name="SaveButton" id="SaveButton" onclick="javascript:document.getElementById('action').value='validate'; formname.submit();" href="#" >Save</a>
The onclick function now works in all IE versions it used to and IE9.
Related
I have this little piece of code in a site to send the current page by email. It works on Firefox but not in Chrome. I've googled the issue but haven't found any answer. Is there anything I'm doing wrong?
<script>
function emailCurrentPage(){
// In comments, other things I've tried
//window.location.href="mailto:?subject="+document.title+"&body="+escape(window.location.href);
//document.location.href="mailto:?subject="+document.title+"&body="+escape(document.location.href);
document.location="mailto:?subject="+document.title+"&body="+escape(document.location);
}
</script>
<button onclick="emailCurrentPage();">
Send by email
</button>
Thank you.
Change your function:
window.location.href="mailto:?subject="+document.title+"&body="+encodeURI(document.location);
There are many forms with a unique id
<form id='fu_edit_1' method='post' action=''>
....
</form>
<form id='fu_edit_2' method='post' action=''>
....
</form>
Use this js code
var formName = 'fu_edit_'+id;
document.forms[formName].submit();
so here is the code works fine in ff the last version, but in chrome and ie refused to work. However, if you specify the id of the form directly it works, for example:
document.forms["fu_edit_2"].submit();
What is wrong?
In the console, Chrome writes : Uncaught TypeError: Object # has no method 'submit'
I think your problem is with the variable id I would recomend you to this:
alert(id.toString());
Maybe there is an issue with your number converion to string, perhaps alert will surprise you with something like 01 or similar
I've come across this problem multiple times and finally found that if you have a form element in the fu_edit_2 form with a name attribute of submit then document.forms["fu_edit_2"].submit would be a reference to the element and not a method to submit the form. I've found it best to stay away from having any form fields with a name of submit to circumvent this problem.
On this page with captcha demo:
http://www.tutorialcadet.com/demo/ajaxform/
the captcha image is not refreshing (when clicking on the image) in internet explorer. In firefox. chrome, opera it works fine.
It throws in explorer this popu up error:
Line: 155
Error: Object doesn't support this property or method
Then when I check the source code in explorer I see this on line 155:
<td><div id="captchaimage"><img src="captcha/image.php?1311183335" alt="Captcha image" width="132" height="46" align="left" /></div></td>
Then when I click on the image again, another error popup shows up:
Line: 1
Error: Object doesn't support this property or method
When I view the source code I see a ?blank row? on the first row.
Here is the screen what I mean by blank first row:
http://i54.tinypic.com/23ves1j.jpg
Any suggestion how to solve this? This happens only in internet explorer. I am currently using 9. Is this some kind of internet explorer bug or?
None of the JS files define the method refreshimg(), hence the error.
Also captcha.js already has the code to handle the captcha.
Remove the refreshimage(); part from the onclick of the #refreshimg anchor.
The anchor element should now look like:
<a href="SITE_BASE/register/" id="refreshimg" onclick="return false;" title="Click to refresh image">
<img src="captcha/image.php?1311183335" alt="Captcha image" width="132" height="46" align="left" />
</a>
Take out onclick="refreshimg()". That function is not defined anywhere and you don't really need that as the click event is already handled in http://www.tutorialcadet.com/demo/ajaxform/js/captcha.js
I am writing an HTML form that uses a google map, but to reduce the ammount of clutter on the screen I have removed the google interface and replaced it with some simple submit buttons to change the map type (eg Satellite, Hybrid and Normal). The problem that I am having is that IE refuses to accept the: map.setMapType(G_SATELLITE_MAP);
What is confusing me though, is the fact that my application works beautifally in Safari and FF, yet refuses to work at all in IE8.
Just for reference here is the function I am calling:
function map_type_sat()
{
map.setMapType(G_SATELLITE_MAP);
return true;
}
and here is how I am calling it:
<form action ="#" onsubmit="return map_type_sat()">
<input type="Submit" value="satellite">
</form>
can anyone see any issues that would be causing it to not work, or is it an issue with my version of IE having a required plugin to run this command.
I'm not sure why you are using a form submission to set the map type. This may, in fact, be handled differently in IE, potentially causing a full post back even with the '#' target action. Try changing it to use a click handler for a regular input button and omit the form. Note that this also eliminates the need to return a value from the function.
function map_type_sat()
{
map.setMapType(G_SATELLITE_MAP);
}
<input type='button' value='satellite' onclick='map_type_sat()' />
Or, even better,
function set_map_type( type )
{
map.setMapType( type );
}
<input type='button' value='normal' onclick='set_map_type(G_NORMAL_MAP);' />
<input type='button' value='satellite' onclick='set_map_type(G_SATELLITE_MAP);' />
<input type='button' value='hybrid' onclick='set_map_type(G_HYBRID_MAP);' />
Hi all i am writing a Rails application and i include some link_to_remote links
The generated code is
Test
That works perfectly fine on Safari and Firefox but when i try to click the link on IE7 and Opera it does not even hit the server.
Any hints ?
Use a fully qualified URL: http://.....
This is a bad practice to include all of this code in the <a href> tag anyways. I suggest you make a function such as:
function doAjax(url)
{
new Ajax.Request(url, {asynchronous:true, evalScripts:true});
return false;
}
in the javascript code. And change the url to say instead:
<a href="#" onclick="return doAjax('/b10/categories/games?category=Action');">
Test</a>