Reputation: 190
I have a Jquery function, which works in Chrome, but not in Firefox, Does anybody have any idea, what went wrong ?
This function is used to fill a text box with default values. The code logic is correct, as it works correctly in chrome.
$('#filler').change(function(){
//Logic here
var Row = document.getElementById("node-0");
var Cells = Row.getElementsByTagName("td");
var size=(Cells[2].innerText);
var chr=document.getElementById("filler").value;
var fillertxt="";
for (var i=0;i<size;i++)
{
fillertxt+=chr+chr+" ";
}
if(!/[0123456789abcdef]/ig.test(chr))
{
alert("Do use Hexadecimal characters!");
}
else
{
$('#input').val(fillertxt);
}
});
Upvotes: 0
Views: 95
Reputation: 21742
Since you are already using jQuery you might as well use it all the way to ensure cross browser compatibility. Also make sure that you call the .change
inside the document ready function (which $(function(){...})
will ensure)
$(function(){
$('#filler').change(function(){
var size = parseInt($("#node-0 td:nth-child(3)").text(),10),
chr = $(this).val(),
fillertxt="";
for (var i=0;i<size;i += 1) {
fillertxt+=chr+chr+" ";
}
if(!/[0123456789abcdef]/ig.test(chr)) {
alert("Do use Hexadecimal characters!");
} else {
$('#input').val(fillertxt);
}
});
});
Upvotes: 0
Reputation: 318192
Firefox uses the W3C-compliant textContent
property, and not innerText
, which is not supported in Firefox.
$('#filler').change(function(){
//Logic here
var Row = $("#node-0"),
Cells = Row.find("td"),
size = parseInt(Cells.eq(2).text(), 10),
chr= $("#filler").val(),
fillertxt="";
for (var i=0; i < size ; i++) {
fillertxt+=chr+chr+" ";
}
if(!/[0123456789abcdef]/ig.test(chr)) {
alert("Do use Hexadecimal characters!");
}else{
$('#input').val(fillertxt);
}
});
Also, it looks like you are trying to use a string in the for
loop as number of iterations. You either need to parse it as a number, or if it's the strings length, use length
?
Upvotes: 3