php/javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    php/javascript

    ok ive done the validation..... is there a way i can get a value thats in javascript into a php var.....i want to get the value that goes into obj2 into a php var......is it possible?

    Code:
    <script>
      function CopyValue(obj1, obj2)
      {
         var visibleField = obj1;
         obj2.value = visibleField.value;
      }
    </script>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you can send the value to PHP via post, get (form or AJAX) or store it in a cookie. the value will then be available via $_POST, $_GET or $_COOKIE. complex values (like array, object, …) need to be serialized first.

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      im trying to do so without having to refresh

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        then you have to use AJAX.

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          ok....could you point me in the right direction...so far i've had ajax to xml which is not what i need

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            just prepare the value for sending and submit the AJAX request (standard AJAX procedure), use the PHP script as recipient. this will trigger the execution of the script with the given value. I think it's a good idea to let the script return a success value, so you know if something went wrong. you can also abort the AJAX call after sending…

            post back if that doesn't answer your question (I hope I understood you right)

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              i understand what you say but i have never used ajax....is this code any use?

              Code:
              <script type="text/javascript" language="javascript">
                  function makeRequest(url) {
                      var httpRequest;
              
                      if (window.XMLHttpRequest) { // Mozilla, Safari, ...
                          httpRequest = new XMLHttpRequest();
                          if (httpRequest.overrideMimeType) {
                              httpRequest.overrideMimeType('text/xml');
                              // See note below about this line
                          }
                      } 
                      else if (window.ActiveXObject) { // IE
                          try {
                              httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                          } 
                          catch (e) {
                              try {
                                  httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                              } 
                              catch (e) {}
                          }
                      }
              
                      if (!httpRequest) {
                          alert('Giving up :( Cannot create an XMLHTTP instance');
                          return false;
                      }
                      httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
                      httpRequest.open('GET', url, true);
                      httpRequest.send('');
              
                  }
              
                  function alertContents(httpRequest) {
              
                      if (httpRequest.readyState == 4) {
                          if (httpRequest.status == 200) {
                              alert(httpRequest.responseText);
                          } else {
                              alert('There was a problem with the request.');
                          }
                      }
              
                  }
              </script>
              <span
                  style="cursor: pointer; text-decoration: underline"
                  onclick="makeRequest('test.html')">
                      Make a request
              </span>

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by anfetienne
                i understand what you say but i have never used ajax....is this code any use?
                sure, you need to replace "test.html" by your script name (see your other thread) and define in alertContents() what you want to do with the return value.

                Comment

                • Ciary
                  Recognized Expert New Member
                  • Apr 2009
                  • 247

                  #9
                  since you're problem is mainly php based, ill answer on this thread

                  Originally posted by anfetienne
                  what it is.....its a paypal form but i want to save the form details into a database before it goes to paypal then once the paypal purchase is complete the user would be redirected to a page to confirm their email address so a confimation email is sent to them with a username and password....i'v e had to go about it this way because paypal do not allow fo extra confirmation emails and refuse to add that option on any account, at 1st i tried to use curl but paypal doesn't allow that....so the only way was with javascript/ajax so it does it all on the same page then the user can just click submit and it will go straight to paypal
                  so, you need an update-query, your code to contact Paypal and a mail function. that a lot but it can be done.

                  the update query is the one i gave you. you only need to specify it more. for the paypal code, i presume you already have it. a mail function is easy to implement.
                  Code:
                  $to      = $mail;
                  $subject = 'Confirmation';
                  $message = $myMessage;
                  $headers = 'From: noreply@mysite.com' . "\r\n" .
                      'Reply-To: me@mysite.com' . "\r\n" .
                      'X-Mailer: PHP/' . phpversion();
                  
                  mail($to, $subject, $message, $headers);

                  Comment

                  Working...