2012-10-16 36 views
0

我使用的是joomla 1.5,需要添加一個有條款和條件名稱的複選框。我已經使用了下面的代碼,但它沒有完全工作。它的警報即使我勾選複選框。Joomla登記表與條款和條件複選框

<script type="text/javascript"><!-- 

function checkAgree() { 
    var agree = document.getElementById('formAgree');   
    if (!agree.checked) { 
     alert('To become a member you must agree to our terms of service!'); 
     return false; 
    } 
    return true; 
} 

--></script> 
<form action="<?php echo JRoute::_('index.php?option=com_user'); ?>" method="post" id="josForm" name="josForm" class="form-validate" onsubmit="return checkAgree();"> 

<?php 

// Terms of Service 

$tokenHTML = str_replace('type="hidden"','id="formAgree" type="checkbox"',JHTML::_('form.token')); 

$tosURL = "tos.html"; // REPLACE THIS! 

?> 
<tr> 
    <td height="40" style="vertical-align: top;"> 
     <label> 
     Terms of service:   
     </label> 
    </td> 
    <td> 
     <iframe src="<?php echo htmlentities($tosURL); ?>" width="307" height="150"></iframe> 
    </td> 
</tr> 
<tr> 
    <td colspan="2"> 
    <p><?php echo $tokenHTML; ?> <b>Agree to terms of service.</b> *</p> 
    </td> 
</tr> 
<tr> 
+0

任何幫助,可能是這種問題? –

+0

'checkAgree()'函數中'agree'的值是什麼?檢查控制檯。 –

回答

0
if ($("#formAgree").not(":checked")) { 
    alert('To become a member you must agree to our terms of service!'); 
    return false; 
} 
return true;