2015-01-19 2 views
-1

Мне нужно создать страницу всплеска T & C, посредством которой пользователь отметит это поле, а затем кнопка отправки включит и переадресует их на правильную страницу.проблема с документом.getElementById(). Onclick

В настоящее время я не могу понять, почему следующий код делает условие CheckBox активной ссылки - нажав на нее, чтобы установить флажок загружает страницу с window.open

Если я закомментировать две строки window.open это все работает по назначению, но без функции ссылок. Очевидно, я пытаюсь создать страницу, которая работает на всех мобильных и настольных клиентах, иначе я бы использовал встроенный onclick в кнопке html.

Спасибо за вашу помощь ...

<script> 
 
function disableSubmit() { 
 
    document.getElementById("submit").disabled = true; 
 
} 
 

 
    function activateBox(element) { 
 

 
     if(element.checked) { 
 
     document.getElementById("submit").disabled = false; 
 
\t \t document.getElementById("submit").value = "Press here to go online"; 
 
\t \t document.getElementById("submit").onclick= window.open('<?php print $grant_url ?>'); 
 
\t \t document.getElementById("submit").ontouchstart= window.open('<?php print $grant_url ?>'); 
 
     } 
 
     else { 
 
     document.getElementById("submit").disabled = true; 
 
\t \t document.getElementById("submit").value = "Please agree to T&C's"; 
 
     } 
 

 
    }; 
 
</script>
<form> 
 
     <input type="checkbox" name="terms" id="terms" onchange="activateBox(this)" autofocus /> 
 
     I Agree to the Terms & Conditions <br> 
 
    
 
     <input class="button" name="submit" value="Please agree to T&C's" id="submit" title="Continue to the Internet" /> 
 
</form>

ответ

0

Это должно работать (обертывание window.open звонков в анонимных функциях)

<script> 
function disableSubmit() { 
    document.getElementById("submit").disabled = true; 
} 

    function activateBox(element) { 

     if(element.checked) { 
     document.getElementById("submit").disabled = false; 
     document.getElementById("submit").value = "Press here to go online"; 
     document.getElementById("submit").onclick= function() { window.open('<?php print $grant_url ?>'); } 
     document.getElementById("submit").ontouchstart= function() { window.open('<?php print $grant_url ?>'); } 
     } 
     else { 
     document.getElementById("submit").disabled = true; 
     document.getElementById("submit").value = "Please agree to T&C's"; 
     } 

    }; 
</script> 
+0

Это сделали работу хорошо. Благодаря! – JBondoux

Смежные вопросы