Javascript problems with IE8 - javascript

I'm trying to disable an input with JavaScript or jQuery
//document.getElementById("monto").disabled=true;
$(document).ready(function(){
$("#monto").attr("disabled", "disabled");
});
The code works fine in chrome, Firefox, and some versions of IE, but doesn't work with IE 8,
also tried with Hide/show but doesn't work too.
I know the best solution is to upgrade, but my boss thinks our clients are too dumb to do that.

try this article from stackoverflow :)
var disableSelection = function(){
$("#elementId").prop("disabled", true);
};
var enableSelection = function(){
$("#elementId").prop("disabled", false);
};

Related

How can I navigate to a URL using JavaScript through IE?

How can I navigate to a URL using JavaScript through IE, I have tried most of the functions for JavaScript, and they doesn't work for IE.
window.location.href = ''; //doesn't work for IE
window.location = ''; //doesn't work for IE
window.open(""); //does work for IE but it opens it in a new tab and I don't want this
Please I need help with that.
Thank You.
EDIT!!!
window.location.href = ''; //works well for IE, the problem was that I was using jQuery to build my HTML and solved by: jQuery.mobile.navigate("url.html#subPg");
try this
self.location=”top.htm”;
tested in IE6,IE7
All the methods below should work in actuality -
1,
window.location.href=”login.jsp?backurl=”+window.location.href;
2,
window.history.back(-1);
3,
window.navigate(”top.jsp”);
4,
self.location=”top.htm”;
5,
top.location=”error.jsp”;
Try this :
<script language="javascript">
window.navigate("");
</script>
Or this :
<script language="JavaScript">
self.location="";
</script>
-Mohamed Shimran

wierd way to get chrome, IE 8 and firefox to submit the same form

This is the only way I found to get all three browsers to submit the form without problems. Is there an obvious reason why this is so? A more elegant solution to this? I'm using jQuery 1.9. Chrome is the odd man out here, as the code in the else is sufficient to submit via IE and Firefox.
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
document.getElementById('myForm').method='POST';
document.getElementById('myForm').submit();
}
else{
document.forms[0].method='POST';
document.forms[0].submit();
}
}
jQuery should already provide a cross-browser way to submit a form. Try:
var $form = $("#myForm");
$form.attr('method', 'post');
$form.submit();
The way that works in Chrome will work in the others also, so just use that:
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
var frm = document.getElementById('myForm');
frm.method = 'POST';
frm.submit();
}
Or using jQuery all the way:
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
$('#myForm').attr('method', 'POST').submit();
}
This is for some older Chrome versions compability. Normally document.forms[0] works as well on Chrome as on other browsers. Easiest way to check, open Chrome console and write console.log(document.forms[0]); - works fine.

Javascript/jQuery not working in IE

This code works in all browsers except for IE. Anything I can do to add support for it?
<script type="text/javascript">
$(document).ready(function() {
var currentArrayNum = 2;
$('#names').on({
blur: function() {
currentArrayNum += 1;
var name = $("<p><input class='input' type='text' name='guests[]' value='' /></p>");
var nullFields = 0;
$(this).closest('div#names').find('input.input').each(function(){
if($(this).val() == ""){
nullFields++;
}
});
console.log(nullFields);
if(nullFields <= 1){
$('#names').append(name.fadeIn(500));
$('#leftbox').scrollTop($('#leftbox')[0].scrollHeight);
}
}
}, 'input');
});
</script>
It should mean that extra input fields are added. You can see it in action (in FF, Chrome, Safari etc) under 'Enter names for the guestlist' here.
EDIT
Tested in IE9 but doesn't work for me.
I should also ask if there's a way of testing in different versions of IE (and othe browsers) on a Mac?
Note that in some (all?) versions of IE, you need to have developer ("F12") tools open for console.log to work, otherwise console is undefined and so console.log() throws an error.
That may be your issue.
I know your question is about a week old but Im not sure if you found a solution or the reason for the cross-browser issues. I was recently working on a custom modal pop up window and I needed to find my scrollTop. Trust me, I love jQuery to death and I use it everyday but sometimes you need to use some good ol' javaScript. I.E accesses the body of the DOM differently than say Chrome or FF.
//I.E.
document.documentElement.scrollTop;
//Chrome, FF, etc.
document.body.scrollTop;
Basically, create a script that detects the user's browser and then include a conditional statement that will assign the value the appropriate way.
//Detect Browser
if (clientBrowser == "IE") {
currTopPos = document.documentElement.scrollTop;
} else {
currTopPos = document.body.scrollTop;
}
I created a script for one of the current projects Im working on, let me know if you would like to take a look at it.

Getting unload to work cross-browser's with a button

I am wondering if I can have the unload method in Javascript do a button.click; or a document.getElementById('target').click(), now I am working on different methods for different browsers but I can't seem to get them it working together.
The reason for this is I want to clear the information in the browser but I can't seem to get the unload method to work right. But I don't even know if the unload method is capable of doing a button.click or a document.getElementById('target').click(); Is there like a list of things this method can or cannot do? Here is the code I am trying to get working:
window.onunload=leave;
function leave() {
// For Internet Explorer only.
if (navigator.appName == "Explorer"){
document.getElementById('kioskform:broswerCloseSubmit').click();
}
// For Chrome only
if (navigator.appName == "Chrome"){
// add code for Chrome to use.
}
// for Safari only
if (navigator.appName == "Safari"){
// add code for Safari to use
}
// for Firefox only
if (navigator.appName == "Firefox"){
// add code for Firefox to use
}
}
So far the only thing working is IE but the other web browsers are not liking the code in the document. But I want to try other methods for the other browsers I am working with. But I can't seem to get browser detection to work at all, any idea's or suggestions or advice is greatly appreciated thank you.
Some browsers (Chrome / FF) does not support the window.onunload method.
See: http://bugs.jquery.com/ticket/10509

pushState fallback for Internet Explorer?

I know that IE does not support pushState, but I want a way for my users with a modern browser to enjoy the benefits while the users using older browsers don't make use of it.
Currently, the javascript code prevents my tabbed navigation from working completely in IE, which means that cannot see a lot of the content.
Anyone know a solution for my problem?
Here's my JavaScript code:
var tabContents = $(".tab_content").hide(),
tabs = $(".tab_nav li");
tabs.first().addClass("active").show();
tabContents.first().show();
tabs.click(function() {
var $this = $(this),
activeTab = $this.find('a').attr('href');
history.pushState(null, '', activeTab);
if(!$this.hasClass('active')){
$this.addClass('active').siblings().removeClass('active');
tabContents.hide().filter(activeTab).fadeIn();
}
return false;
});
$(window).bind('popstate', function(){
$.getScript(location.href);
});
Try the jQuery BBQ: Back Button & Query Library. I've had great success using it.

Categories

Resources