I need an alternate solution for document.all.item(id,0). Its working fine in windows7 IE browser but as per IE they have mention that it will not support for IE11 browser so kindly any one help me to sort this issue.
See code below:
function displayById(id){
var tid = document.all.item(id,0);
tid.style.display ='inline';
}
document.getElementById(id); should achieve the result you're looking for. This will get the HTML element with the id of id
Related
I am dynamically creating a text area, based on the number of each user, comment for each user.
i am using the below code to do the same, it works fine in all the browser except IE8.
$(template1).find('textarea').attr({"id":'selfasgn'+aud.ASGN_ID,"onchange":'captureSelfComments('+aud.ASGN_ID+')'})
note that $(template1) is clone of one of the element in node.
template1 = reviewTemplate.clone(true);
function captureSelfComments(p_asgnid){
alert('caling captureSelfComments');
}
I tried below code, but its getting called when this element gets constructed or appened to the DOM. so i removed it.
$(template1).find('textarea').live('change',captureSelfComments(aud.ASGN_ID))
am I doing anything wrong here ?
For IE, try propertychange() as described here since IE may not always support the change event.
var lowIE = /msie (6|7|8)/gi.test(window.navigator.userAgent);
$(template1).find('textarea').live(lowIE ? 'propertychange' : 'change',captureSelfComments(aud.ASGN_ID));
Generally, it is not a good idea to do user agent sniffing but we are talking about IE... which is basically also not a good idea, generally :)
I currently build a javascript which will change the bgColor of the table row. All is well when I tested it with Google Chrome, but after I try it on IE9 then it just...sometime works, sometimes do not...Do someone here know how can I fixed it? Am I going to throw away the java scripts and build another 1? Below is the related code...
Updated:
I manage to change the bgColor using javaScript, but it does not perform correctly until I press F12 or double click the table rows for IE9.
I found out that Website with JS doesn't work in IE9 until the Developer Tools is activated is almost 100% with my situation and there are many more. But, I do not have any code which related to the console or console.log in my program and I had try many methods to find out what is the problem.
But at the end, still back to zero. No idea what is going wrong, need some helps at here... Thanks in advanced
JavaScript
<SCRIPT LANGUAGE="JavaScript">
//......
//......
function setColor(){
if(selectedRow != ""){
selectedRow.bgColor = originColor;
}
var x = getObjectById("row");
x.bgColor = "#CCCCFF";
selectedRow = x;
}
</SCRIPT>
HTML
<TD ... onclick="setColor();"></TD>
Need some hints.
I'm not sure what getObjectById is doing, but you should be setting style.backgroundColor on your HTMLElement rather than the bgColor property. The bgColor property matches with the attribute of the same name, and this attribute has been depreciated since HTML 4.01 and obsolete in HTML5.
elm.style.backgroundColor = '#CCCCFF';
I have a MVC app.
I have written JS code below in the "Create" view. The code below code works perfectly in Google chrome and Mozilla Firefox; but it's not working in IE 8.
$('#PaymentType').change(function(){
var ptype=document.getElementById("PaymentType").value;
});
So I changed it to the code below and it works... on IE 8 as well
$('#PaymentType').change(function(){
var ptype = $(this).val();
});
Now, the problem is that I am not going to use getElementById anymore...
What if I want to get the values from another control? Which alternate option is there available to getElementById?
You just use $('#otherId').val() to get the value.
Also on a side note in your second code example you could've just used var ptype = this.value;
If you're using jQuery you don't need to use document.getElementById anymore.
I would be interested to know why it doesn't work though, it looks like it should.
This might be stupid question, but...
Question: How to get the appended HTML to the console's log? I am 100 % sure that my appended HTML is broken and for future purposes I would like to know how to get the result to log? I am trying to implement small software for Android using Jquery Mobile and Phonegap.
Of course you can check my function too, because appends are not correct at the moment.
EDIT: QUESTION 2:
Could you find the reason why I can't see the text PÖÖ/POO. So the second TR is totally missing, but why?
function populateTable(){
console.log("###########populateTable()#############");
$("#table").find('tbody')
.append($('<tr>')
.append($('<td>')
.append($('<img>')
.attr('src', 'images/cart_1.jpg')
.text('Image cell')
)
.append($('</td>')))
.append($('</tr>'))
.append($('<tr>')
.append($('<td>')
.append($('PÖÖ'))
.append($('</td>'))
.append($('</tr>'))
)));
var strinki = JSON.stringify($("#table"));
console.log("2....*******************>>>>>>>>>>>>>>>" +strinki);
}
What you want is console.log($('#table')[0]) so you get the DOM element.
If you prefer a HTML string because you are using a browser with inferior debug tools (in Firebug I can easily view a DOM subtree): console.log($('#table').html())
That was it :) It was so simple that I should know that by meself :)
var strinki = $("#table").html();
When I select any option in list then it should print its value in textbox(all html).
I tried
stafflist.setAttribute("onchange", "javacript:document.getElementById('id_17_enrolpassword').value = this.value;");
Its working in IE8+ and all modern browsers but not in IE7.
Also tried
stafflist.addEventListener('onchange',"javacript:document.getElementById('id_17_enrolpassword').value = this.value;",false);
So what changes I should do here?
IE only fires the onchange event when the element loses focus - if you were to click outside the element or tab to a different element it should fire then.
You can get around this by using a different even, for example onkeypress
1) the javascript: label is only needed if the first script on the page is vbscript.
2) does this work better?
document.getElementById('stafflist').onchange=function(){
document.getElementById('id_17_enrolpassword').value = this.value;
}
?
do it this way -
stafflist.onchange = function(){
document.getElementById('id_17_enrolpassword').value= this.value;
}
I know this doesn't truly answer the question at hand, but, can't you use something like jQuery to code these sort of even handlings?
The code is a bit more readable (IMHO), and you don't have to deal this these cross-browser scripting issues yourself.