2013-03-19 40 views
1

下面的JavaScript和功能完美無瑕的作品中的Joomla 1.5,但似乎它並沒有在2.5的工作 - 任何度假。它的一個資格計算器JavaScript的作品在1.5,但在的Joomla不起作用2.5

似乎驗證不工作因爲每當表單提交 - 驗證是沒有得到2.5執行,PHP 5.3

<td><input name="calc" type="button" class="red-btn" onClick="javascript:return(validate())" style="width:65" value="Calculate Eligibility" /> 
    <input type="reset" name="reset" value="Reset" class="red-btn" /></td> 

我不能夠點擊提交,即使我點擊沒有反應

下面是這是腳本稱爲

function validate() 

{ 
var income,Coapplnincome,vOtherLonAmt,deduct,IntRate,LoanTenure; 
var totInterest,totemi,ElgibleLon; 
if(!document.eligib_calc.income.value) 
{ 
     alert("Please enter Applicants gross monthy income"); 
    document.eligib_calc.income.focus(); 
    return false;   
} 
    if(isNaN(document.eligib_calc.income.value)) 
{ alert("Please Enter Numeric value for Income"); 
    document.eligib_calc.income.focus(); 
    return false;   
} 
if(!document.eligib_calc.Coapplnincome.value) 
    document.eligib_calc.Coapplnincome.value=0; 
else if(isNaN(document.eligib_calc.Coapplnincome.value)) 
{ alert("Please Enter Numeric value for Co applicant Income"); 
    document.eligib_calc.Coapplnincome.focus(); 
    return false;   
} 
if(!document.eligib_calc.OtherLonAmt.value) 
    document.eligib_calc.OtherLonAmt.value=0; 
else if(isNaN(document.eligib_calc.OtherLonAmt.value)) 
{ alert("Please Enter Numeric value for other loans"); 
    document.eligib_calc.OtherLonAmt.focus(); 
    return false;   

} 



if(!document.eligib_calc.deduct.value) 

    document.eligib_calc.deduct.value=0; 

else if(isNaN(document.eligib_calc.deduct.value)) 

{ alert("Please Enter Numeric value for Deductions"); 

    document.eligib_calc.deduct.focus(); 

    return false;   

} 

if(!document.eligib_calc.IntRate.value) 

{ 

    alert("Please enter Interest Rate(in %)"); 

    document.eligib_calc.IntRate.focus(); 

    return false;   

} 

    if(isNaN(document.eligib_calc.IntRate.value)) 

{ alert("Please Enter Numeric value for Interest Rate(in %)"); 

    document.eligib_calc.IntRate.focus(); 

    return false;   

} 



if(!document.eligib_calc.LoanTenure.value) 

{ 

    alert("Please enter Loan Tenure"); 

    document.eligib_calc.LoanTenure.focus(); 

    return false;   

} 

if(isNaN(document.eligib_calc.LoanTenure.value)) 

{ alert("Please Enter Numeric value for Loan Tenure"); 

    document.eligib_calc.LoanTenure.focus(); 

    return false;   

} 





income=document.eligib_calc.income.value; 

Coapplnincome=document.eligib_calc.Coapplnincome.value; 

OtherLonAmt=document.eligib_calc.OtherLonAmt.value; 

deduct=document.eligib_calc.deduct.value; 

IntRate=document.eligib_calc.IntRate.value; 

LoanTenure=document.eligib_calc.LoanTenure.value; 



totInterest=(parseInt(income)+parseInt(Coapplnincome))-(parseInt(OtherLonAmt)+parseInt(deduct)); 

totemi=EMI(100000,document.eligib_calc.IntRate.value,document.eligib_calc.LoanTenure.value); 

ElgibleLon=(totInterest*(0.4)/(totemi)); 

//document.eligib_calc.emi.value=Math.ceil(totemi)+" per Lakh"; 



ElgibleLon=ElgibleLon*100; 

ElgibleLon=Math.round(ElgibleLon); 

ElgibleLon=ElgibleLon/100; 

document.eligib_calc.ElgibleLon.value=ElgibleLon+" Lakhs";  

     } 

     function EMI(vAmt,IntRate,LoanTenure) 

     { 

var terms; 

var numAmt,denAmt; 

var emiv; 

terms=12; 



numAmt=vAmt*Math.pow((1+IntRate/(terms*100)),LoanTenure); 



denAmt=100*terms*(Math.pow((1+IntRate/(terms*100)),LoanTenure)-1)/IntRate; 



emiv=12*(numAmt/(denAmt*12)); 



emiv=Math.round(emiv); 



return emiv; 


     } 
     </script> 
+3

如果您不介意,你會告訴我們什麼不行嗎? – Ibu 2013-03-19 02:33:22

+1

有沒有什麼在javascript的錯誤控制檯 – 2013-03-19 08:27:36

+0

嗨 - 我已經編輯了更多的細節,其資格計算器的帖子,現在雖然我嘗試點擊提交 - 它只是沒有點擊,我正在使用onClick =「javascript:return(驗證())「 - 似乎它不工作在PHP 5.3 – user2130961 2013-03-20 16:18:51

回答

0

腳本將起作用。但提醒您在使用jQuery兩種方式

1)http://docs.joomla.org/JDocument
http://docs.joomla.org/JDocument/addScriptDeclaration

2)顯示您的警報indise標籤
hopfuly幫助

例子:

function getJavaScript($message) { 
$javascript .= 'if(window.addEventListener){ // Mozilla, Netscape, Firefox' . "\n"; 
$javascript .= ' window.addEventListener("load", function(){ alert("' . $message . '");}, false);' . "\n"; 
$javascript .= '} else { // IE' . "\n"; 
$javascript .= ' window.attachEvent("onload", function(){ alert("' . $message . '");});' . "\n"; 
    $javascript .= '}'; 
    return $javascript; 
} 

$doc =& JFactory::getDocument(); 
$doc->addScriptDeclaration(getJavaScript('This will appear in an alert box after the page loads.'));