getelementbyid does not work in firefox
Posted
by gaurab
on Stack Overflow
See other posts from Stack Overflow
or by gaurab
Published on 2010-04-29T18:51:03Z
Indexed on
2010/04/29
18:57 UTC
Read the original article
Hit count: 437
JavaScript
hi, this below mentioned code works perfect in internet explorer but not in firefox... i get an error in line in firefox: document.getElementById("supplier_no").value= values_array[0]; that getElementById returns null. how to solve the problem?
var winName; //variable for the popup window
var g_return_destination = null ; //variable to track where the data gets sent back to.
// Set the value in the original pages text box.
function f_set_home_value( as_Value )
{
if (document.getElementById(g_return_destination[0]).name == "netbank_supplier_name_info" )
{
//clear the old values
for (selnum = 1; selnum <= 5; selnum++)
{
document.getElementById("expense_account"+selnum).value = "";
document.getElementById("expense_account_name"+selnum).value = "";
document.getElementById("expense_vat_flag"+selnum).value = "off";
document.getElementById("expense_vat_flag"+selnum).checked = "";
document.getElementById("expense_vat_amount"+selnum).value = "";
document.getElementById("expense_vat_code"+selnum).value = "";
document.getElementById("expense_period"+selnum).value = "";
document.getElementById("expense_date"+selnum).value = "";
if (selnum!=1) {//these are sometimes defaulted in, and in any case you will always have line1
document.getElementById("expense_more_dept"+selnum).value = "";
document.getElementById("expense_more_prj"+selnum).value = "";
document.getElementById("expense_more_subj"+selnum).value = "";
}
document.getElementById("expense_amount"+selnum).value = "";
}
var values_array = as_Value[0].split("!");
document.getElementById("supplier_no").value= values_array[0];
document.getElementById("supplier_bankAccount_no").value= values_array[1];
str = values_array[2] ;
str = str.split(";sp;").join(" ");
document.getElementById("default_expense_account").value= str;
document.getElementById("expense_account1").value= str;
document.getElementById("expense_more_sok1").disabled= false;
str = values_array[3] ;
str = str.split(";sp;").join(" ");
document.getElementById("payment_term").value= str;
strPeriod = calcPeriod(str,document.getElementById("due_date").value);
document.getElementById("expense_period1").value = (strPeriod);
strExpenseDate = calcExpenseDate(str,document.getElementById("due_date").value);
document.getElementById("expense_date1").value = (strExpenseDate);
str = values_array[4] ;
str = str.split(";sp;").join(" ");
document.getElementById("expense_account_name1").value= str;
str = values_array[5] ;
str = str.split(";sp;").join(" ");
document.getElementById("expense_vat_code1").value= str;
if (str == 0) {
document.getElementById("expense_vat_flag1").checked= '';
document.getElementById("expense_vat_flag1").disabled= true;
}else{
document.getElementById("expense_vat_flag1").checked= 'yes';
document.getElementById("expense_vat_flag1").value= 'on';
document.getElementById("expense_vat_flag1").disabled= false;
}
str = values_array[6] ;
str = str.split(";sp;").join(" ");
document.getElementById("supplier_name").value= str;
var str = values_array[7];
str = str.split(";sp;").join(" ");
str = str.split("&cr;").join("\r");
document.getElementById("netbank_supplier_name_info").value= str;
strx = justNumberNF(document.getElementById("amount").value);
document.all["expense_vat_amount1"].value = NetbankToDollarsAndCents(strx * (24/124)) ;
document.getElementById("amount").value=NetbankToDollarsAndCents(strx);
document.getElementById("expense_amount1").value = document.getElementById("amount").value;
document.getElementById("expense_amount2").value = '';
document.getElementById("expense_account2").value= '';
//document.getElementById("expense_vat_flag2").value= '';
document.getElementById("expense_vat_amount2").value= '';
document.getElementById("expense_amount3").value = '';
document.getElementById("expense_account3").value= '';
//.getElementById("expense_vat_flag3").value= '';
document.getElementById("expense_vat_amount3").value= '';
document.getElementById("expense_amount4").value = '';
document.getElementById("expense_account4").value= '';
//document.getElementById("expense_vat_flag4").value= '';
document.getElementById("expense_vat_amount4").value= '';
document.getElementById("expense_amount5").value = '';
document.getElementById("expense_account5").value= '';
//document.getElementById("expense_vat_flag5").value= '';
document.getElementById("expense_vat_amount5").value= '';
str = values_array[8] ;
str = str.split(";sp;").join(" ");
if (str=="2"){
document.frmName.ButtonSelPeriodisering1.disabled=false;
document.frmName.ButtonSelPeriodisering1.click();
}
winName.close();
}
}
//Pass Data Back to original window
function f_popup_return(as_Value)
{
var l_return = new Array(1);
l_return[0] = as_Value;
f_set_home_value(l_return);
}
function justNumberNF(val){
val = (val==null) ? 0 : val;
// check if a number, otherwise try taking out non-number characters.
if (isNaN(val)) {
var newVal = parseFloat(val.replace(/[^\d\.\-]/g, '.'));
// check if still not a number. Might be undefined, '', etc., so just replace with 0.
return (isNaN(newVal) ? 0 : newVal);
}
// return 0 in place of infinite numbers.
else if (!isFinite(val)) { return 0; }
return val;
};
function NetbankToDollarsAndCents(n) {
var s = "" + Math.round(n * 100) / 100 ;
var i = s.indexOf('.') ;
if (i < 0) {return s + ",00" } ;
var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3) ;
if (i + 2 == s.length) {t += "0"} ;
return t.replace('.',',') ;
}
© Stack Overflow or respective owner