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.
Related
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
I'm trying to select drop-downs and check them, so I'm using this code to do so - document.getElementsByTagName('select'); but the problem I'm facing is that I've got several forms on one page and I want to choose only drop-downs from form called myform3 for example!
I found one example it looks like this - myform3.document.getElementsByTagName('select'); but it only works in IE
Could you tell me how to do that in every browser?
Try:
document.forms['myform3'].getElementsByTagName('select')
It should be
document.myForm3.getElementsByTagName('select');
Not
myForm3.document.getElementsByTagName('select');
Works in other browsers too.
It's working fine..
document.forms["form_name"].getElementsByTagName("select");
I found one example it looks like this - myform3.document.getElementsByTagName('select'); but it only works in IE
myform3.getElementsByTagName would be correct – documentis out of place there.
(You can call getElementsByTagName on every node object to only get nodes that are descendants of it.)
Try this way :
document.forms["myform3"].getElementsByTagName("select");
Set the ID attribute of the form to myform3. Then you can do this:
var myForm = document.getElementById("myform3");
var selects = myForm.getElementsByTagName("select");
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.
I've got the following piece of code:
vote = $('input.vote', $($("ul#statement_forms li.statement")[current])).attr("value");
alert(vote);
Where the variable current is an integer. If i run this in Safari it works as expected (it alerts the value of vote), but not in IE, though, when i run this:
alert($('input.vote', $($("ul#statement_forms li.statement")[current])).attr("value"));
IE Also alerts the value, so i guess the problem is that it wont assign the value to the variable.
I tried using jQuery 1.5.1, 1.3.1 and 1.2.6 but no difference.
I'm hoping one of you guys can help me out..
Thanks!
Vote isnt a global variable, it's defined at this posted line
You're missing var before vote to actually declare the variable at this point. Safari apparently doesn't care, but IE doesn't like it.
On a side note: jQuery has .val() and .val("something") functions to retrieve and set the value of input and select elements.
I am trying to add a table row to a table using .after() but it's not working in any IE, I keep getting this error "Object required" and the error seems to be coming from line 5151 in my jQuery library.
Here is my code:
$('#view').live('click',function(){
var parent = $(this).parent();
parent.after("<tr><td>Test</td></tr>");
});
Any ideas?
A likely reason is that the HTML code isn't valid without a table tag.
Create the elements as separate elements instead:
parent.after($('<tr/>').append($('<td/>').text('Test')));
I would definitely validate your HTML first; this kind of thing often fails beacuse IE is less "generous" when things aren't valid.
Do you know what parent is? is it definitely a tr?
Works fine for me in IE, FF and Chrome: demo.