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 3404672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:24:42+00:00 2026-05-18T05:24:42+00:00

var text = $(input#text).val(); if (text == ) { $(input#text).focus(); alert(Please complete all fields);

  • 0
var text = $("input#text").val();
    if (text == "") {
          $("input#text").focus();
          alert("Please complete all fields");
          return false;
    }

I have this jquery above to validate a textarea called “text”. This, along with other values, get .ajax sent to a php page for sending an email. The email comes through fine with everything else in ok, but the textarea comes through as “undefined”? Any ideas? Do i need to post some more code?

EDIT:

Rest of the code:

the php:

                      $email = $_REQUEST['email'] ;
                      $text = $_REQUEST['text'] ;
                      $name = $_REQUEST['name'] ;
                      $detail = "Name: ".$name."\nMessage: ".$text;
                      mail( "xxxxxxxxx", "Subject: Contact Form",
                      $detail, "From: $email" );
                      echo "Thank you for getting in touch";

complete jquery:

$(function() {

$(‘#submit’).live(‘click’,function(){

    var name = $("input#name").val();
    if (name == "") {
          $("input#name").focus();
          alert("Please complete all fields");
          return false;
    }

    var email = $("input#email").val();
    if (email == "") {
          $("input#email").focus();
          alert("Please complete all fields");
          return false;
    }

    var text = $("input#text").val();
    if (text == "") {
          $("input#text").focus();
          alert("Please complete all fields");
          return false;
    }

    var dataString = 'name=' + name + '&email=' + email + '&text=' + text;
    //alert (dataString);return false;

    $.ajax({
  type: "POST",
  url: "mailform.php",
  data: dataString,
  success: function() {
    alert("Thanks, we will be in touch soon");
  }
 });
return false;
});

});

The html:

<form method='post' action='mailform.php' class="form">

                <p class="name">
                <label for="name">Name</label>
                    <input type="text" name="name" id="name" />    
                </p>

                <p class="email">
                    <label for="email">E-mail</label>
                    <input type="text" name="email" id="email" />            
                </p>

                <p class="text">
                    <label for="text">Nature of Enquiry</label>
                    <textarea id="text" name="text"></textarea>
                </p>

                <p class="submit">
                    <input type="submit" id="submit" value="Send" />
                </p>

            </form>
  • 1 1 Answer
  • 5 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-18T05:24:43+00:00Added an answer on May 18, 2026 at 5:24 am

    I had a similar problem and my problem was with the php code. Try yo have a look there see if the #textarea gets _POST – ed correctly.

    I am using this and works perfectly for me:

    //we need to get our variables first
    
    $email_to =   'xxxxx@yahoo.com'; //the address to which the email will be sent
    $name     =   $_POST['name'];  
    $email    =   $_POST['email'];
    $subject  =   $_POST['subject'];
    $message  =   $_POST['message']. "\n\n";
    
    /*the $header variable is for the additional headers in the mail function,
     we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
     That way when we want to reply the email gmail(or yahoo or hotmail...) will know 
     who are we replying to. */
    $headers  = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";
    
    if(mail($email_to, $subject, $message, $headers)){
        echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..      
    }else{
        echo 'failed';// ... or this one to tell it that it wasn't sent    
    }
    

    Not sure what’s going on, like the other user said I believe to be a problem with the way the data is being carried over to the php script.

    Try to look into $.post and serialize() functions that jquery can offer:

    to give you an idea:

        var error = false;
        var name = $('#name').val();
        var email = $('#email').val();
        var subject = $('#subject').val();
        var message = $('#message').val();
    

    — Due some checks to see if the info is correct—

        if(error == false){
            //#contact_form has all the variables that get serialized and sent to the php
              and you can get a message back to check if everything went okay.
            $.post("your_php_code.php", $("#contact_form").serialize(),function(result){
                //and after the ajax request ends we check the text returned
                if(result == 'sent'){
                    //if the mail is sent remove the submit paragraph
                     $('#cf_submit_p').remove();
                    //and show the mail success div with fadeIn
                    $('#mail_success').fadeIn(500);
                }else{
                    //show the mail failed div
                    $('#mail_fail').fadeIn(500);
                    $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
var func = function() { $(this).hide(); $parent = $(this).parent(); $parent.removeClass('my_signature_mouseover'); var text = $(this).val();
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
i have a page layout like this <input id=name class=mandotary type=text> <label for=name>Name must
JavaScript: $('.addTable').live('click', function () { var appendTxt = <table id='tab1'> <tr><td><input type='text' name='input1' /></td><td><input
$(document).ready(function() { function countChecked() { var n = $(input:checked).length; $(div).text(n + (n <= 1
I am using replace method of string, var text = this ex is not
I have a text input field, on which when you click a json request
I have a function that sets text input's to whenever they are clicked/focused on.
I have some jQuery code, where you click on text and it changes into

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.