Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6012879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:28:04+00:00 2026-05-23T02:28:04+00:00

So I had this working fine with pure PHP. When you hit submit the

  • 0

So I had this working fine with pure PHP. When you hit submit the form was submitted and the PHP page was loaded. So I tried to implement AJAX so that the page didn’t have to reload when the form was submitted, but now the variables are never reaching the PHP script.

Here’s what I’ve got:

<form method="get" action="sms.php">
<input type="text" name="number" value="Phone number" /><br />
<textarea type="text" name="message" rows="5" cols="20"></textarea><br />
<input type="button" onclick="ajaxFunction()" value="Send" />
</form>

The AJAX js file:

   function ajaxFunction(){
    var ajaxRequest;

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('confirm');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }
    var number = document.getElementById('number').value;
    var message = document.getElementById('message').value;
    var queryString = "?number=" + number + "&message=" + message;
    ajaxRequest.open("GET", "sms.php" + queryString, true);
    ajaxRequest.send(null); 
}

and finally the php script:

<?php
$number = $_GET["number"];
$message = $_GET["message"];

$client = new SoapClient('http://sms2.cdyne.com/sms.svc?wsdl');
$param = array(
    'PhoneNumber' => $number,
    'LicenseKey' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
    'Message' => $message,
    );

echo "SMS sent.";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:28:05+00:00Added an answer on May 23, 2026 at 2:28 am

    You’re using getElementById() to get the elements:

    var number = document.getElementById('number').value;
    var message = document.getElementById('message').value;
    

    But your HTML elements do not have ID’s. Update them like this:

    <input type="text" ID="number" value="Phone number" /><br />
    <textarea type="text" ID="message" rows="5" cols="20"></textarea><br />
    

    Or change your javascript to use getElementByName().

    However, if adding jQuery is an option, it could be this simple:

    <input type="text" id="number" value="Phone number" /><br />
    <textarea type="text" id="message" rows="5" cols="20"></textarea><br />
    <input type="button" id="submitform" value="Send" />
    
    <script>
    $(document).ready(function() {
      $('#submitform').click(function() {
         var num = $('#number').value();
         var msg = $('#message').value();
         $.get('sms.php',{number: num, message: msg}, function(response) { alert(response); });
      });
    });
    </script>
    

    That giant ajaxFunction() would be replaced by ~8 lines of JS using jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this simple modal contact form working fine but must have broke it
So basically this code was working fine before. I had some computer issues and
Ok, so I had this working just fine before making a few controller additions
I had this working fine yesterday, made some changes and I have no idea
So I had this working perfectly fine, but now for some reason I can't
I had this working fine while using toggle, but I need to make these
I had this embedded map working just fine and now suddenly it just shows
Strangely I had this working before but I reinstalled my system, upgraded to w7
Has anyone else had this issue and found a working solution? I've enabled the
I had a working app on 2.1 and above until I tried to cleanup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.