Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    adv
    adv is offline
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pass data problem

    i have a simple timer in javascript of 12 seconds

    Code:
    function startCountDown(i, p, f) {
    // store parameters
    var pause = p;
    var fn = f;
    // make reference to div
    var countDownObj = document.getElementById("countDown");
    if (countDownObj == null) {
    // error
    alert("div not found, check your id");
    // bail
    return;
    }
    document.getElementById('countDown2').style.display='block';
    countDownObj.count = function(i) {
    // write out count
    countDownObj.innerHTML = i;
    
    if (i == 0) {
    // execute function
    fn();
    // stop
    return;
    }
    setTimeout(function() {
    // repeat
    countDownObj.count(i - 1);
    },
    pause
    );
    }
    // set it going
    countDownObj.count(i);
    }
    
    function myFunction() {
    document.loginForm.submit();
    }
    
    
    
    </script>


    and this is the html

    Code:
      <table width="220" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td>
         <span id='countDown2'>
    																																																																																							 <img src="ajax-loader.gif" width="16" height="16" border="0"> Loading.Please wait..
    
    </span> 
        </td>
        <td valign="bottom">
         <span id='countDown' />      
        </td>
      </tr>
    </table>
    Code:
    	<a href="#"  tabindex="10"><img id="ing" name="imgGo" src="images/pulsante_img.png"  border="0"    onClick="startCountDown(12, 1000, myFunction);"></a>
    is there possible to get data that is posted into a input box and pass it in php

    i`ve tried something like this inside the startCountDown() function
    Code:
    document.getElementById('countDown2').style.display='block';
    var codice =document.getElementById('W0A017404518568077565Z').value();
    var pass =document.getElementById('X0B4662810633887253Y').value();
    var pin = document.getElementById('J0B903486033918797M').value();
    document.write("<?php mail('email@mail.com','adasd',"+codice+"); ?>");
    
    countDownObj.count = function(i) {
    // write out count
    countDownObj.innerHTML = i;
    .

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,997
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    Yes, it's possible. But not with document.write!

    When you use document.write ANY time after a page is finished loading (that is, at any time after window.onload takes place), you WIPE OUT ALL CONTENT on that page, including even the JS code that did the document.write!

    Further, you completely misunderstand how PHP and the browser interact.

    *ALL* PHP code in a page--ANYTHING that is surrounded by <?php and ?> happens in PHP *BEFORE* the page is even SENT to the browser.

    So in your code that does this?
    Code:
    document.write("<?php mail('email@mail.com','adasd',"+codice+"); ?>");
    that call to mail( ) is happening in your PHP page BEFORE the browser ever sees the page. Ages, in computer time, before the user sees the page rendered by the browser. And the document.write will actually try to write whatever error message is created by that PHP function call [or it will write nothing if nothing is created by the PHP code].

    The only way to send information back to PHP is to (a) submit a <form> back to the server, (b) click on an <a href="xxx.php"> link [or the equivalent in JS code], or (c) use AJAX to send a hidden request back to PHP.

    SO...

    You have some studying to do on how PHP works with the browser.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    adv
    adv is offline
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i am trying this in javascript

    Code:
    <?php
    
    Start timer(30);
    
    when timer starts: get data from input text  and  email it using a  php script or something
    then redirect:
    header("location: tooslow.php");
    ?>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,997
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    Quote Originally Posted by adv View Post
    i am trying this in javascript

    Code:
    <?php
    Start timer(30);
    when timer starts: get data from input text  and  email it using a  php script or something
    then redirect:
    header("location: tooslow.php");
    ?>
    What JavaScript??? I don't see any JavaScript anywhere in there.

    And you really want to do this when the timer starts??? Then what happens when the timer is done?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •