JavaScript 可以在 1.5 中运行,但不能在 joomla 2.5 中运行

标签 javascript joomla joomla2.5 joomla1.5

下面的 javascript 和函数在 joomla 1.5 中完美运行,但似乎在 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> 

最佳答案

脚本可以工作。但对于 Alert 你有两种方法

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

2)使用jquery在标签中显示您的警报
希望有帮助

示例:

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.' ) );

关于JavaScript 可以在 1.5 中运行,但不能在 joomla 2.5 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490540/

相关文章:

php - 带/不带表特定引用的 MySQL 查询

.htaccess - HTACCESS RewriteRule 更改 URL 正常但给出 404 页面

joomla - 如何在 Joomla 2.5 中获取模块的标题?

javascript - Simon游戏javascript,如何使用animation()和delay() JQUERY同步按钮的灯光而不互相踩踏?

javascript - 如何检测 jQuery 全局变量何时准备好?

javascript - 无法将文件对象从reactjs发送到nodejs

php - 在php中转义单引号mysql查询

jquery - 有什么方法可以将类添加到 JOOMLA PLUGIN

css - 如果内容很少,如何让页脚保持在页面底部而不自动出现以填充空间?

javascript - 使用handlebars.js显示多个json对象的值