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

The Archive Base Latest Questions

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

form_page.html <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script src=js/process_truck_req.js></script> <script src=js/jquery-1.2.3.pack.js></script> <script

  • 0

form_page.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="js/process_truck_req.js"></script>
    <script src="js/jquery-1.2.3.pack.js"></script>
    <script src="js/runonload.js"></script>
</head>

<div class="prform" id ="request_form">    
    <form name="truckreq" action="" method="post" class="truckreq_form">
        <label for="seltruck" id="seltruck_label"><font class="whitetext">Select Truck</font></label><br />
        <select name="seltruck" id="seltruck">
            <option value="Select a Truck"> Select a Truck</option>
            <option value="2011+Tacoma">2011 Tacoma</option>
            <option value="2008+Tundra">2008 Tundra</option>
            <option value="2000+Tacoma">2000 Tacoma</option>
        </select><br />
        <label class="error" for="seltruck" id="seltruck_error"><font class="redtext">This field is required.</font></label><br />
        <label class="error" for="seltruck" id="seltruck_noavail_error"><font class="redtext">Not Available on selected Dates.</font></label><br />
    </form>

process_request.js

$(function() {
    $('.error').hide();
    $('input.text-input').css({backgroundColor:"#FFFFFF"});
    $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
});

$('input.radio-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
});

$('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
});

$(".button").click(function() {
    // validate and process form
    // first hide any error messages
    $('.error').hide();

    var seltruck = $("#seltruck").val();
    if (seltruck == "Select a Truck") {
        $("label#seltruck_error").show();
        $("#seltruck").focus();
            return false;
        }

        var truckSearch = 'seltruck=' + seltruck + '&outdate=' + outdate + '&indate=' + indate;

        $.ajax({
            type: "POST",
            url: "do_truck_search.php",
            data: truckSearch,
            success: function() {
                var truck_status = $("#truck_status").val();
                if (truck_status == "nopass") {
                    $("label#seltruck_noavail_error").show();
                    $("#seltruck").focus();
                    return false;
                }
            }
        });
    });
});

runOnLoad(function() {
    $("input#projdesc").select().focus();
});

Take input form data from form_page.html, pass to process_request.js for validation. I only displayed seltruck, other form fields are set in form_page.html.

At the .js validation, the fields are check if they are filled out, if not, the error label class is displayed on the form_page.html.

The seltruck form field requires mysql to be queried and checked for availability. I have the do_truck_search.php script working great, but don’t know how to pass the ‘truck_status’ variable from do_truck_search.php back to the .ajax call.

Once back at the .ajax call, I’d like a success: ‘continue’ or error: display the label#seltruck_noavail_error.

any help?

thanks!

UPDATE – can’t get this to work? dataType: “text” in .ajax works though? any thoughts?

do_truck_search.php

if (($unixoutdate >= $dbunixoutdate) && ($unixoutdate <= $dbunixindate) && ($dbtruck == $seltruck_final)){
    $truck_status = "nopass";
    $data2 = array('truck_status' => $truck_status);
    echo json_encode($data2);
}

process_request.js:

$.ajax({
  type: "POST",
  url: "do_truck_search.php",
  data: truckString,
  dataType: "json",
  success: function(data) {
      if (data.truck_status == "nopass"){
          $("label#seltruck_noavail_error").show();
      }
    }
});

UPDATE

I think the reason why the json datatype was unreliable is because a small square (probably a space) is echo’d from the PHP script. Using datatype: ‘text’ and an alert() in the .ajax success callback shows the small square, prior to the actual data text. My dirty solution was to use datatype: text, then just substr the actual data I want to retrieve.

I searched hi/low in the PHP script to find the cause of the echo’d space, but couldn’t find it??

  • 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-28T02:18:33+00:00Added an answer on May 28, 2026 at 2:18 am

    One possible way to do this:

    1. In $.ajax set dataType: "json"
    2. In the PHP script echo json_encode(array("truck_status" => $truck_status));. Note that no other output must be present (so disable your layouts, views etc.)
    3. Change success: function() {...} to success: function(data, status) {...}; now the variable data will contain the key truck_status with whatever you set it to. So access it using data.truck_status.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

html <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title>Untitled Page</title>
I have a form as under <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title>Untitled Page</title> <script type=text/javascript
I have an aspx page defined as follows: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title></title> <script
Here is a simplified version of my page: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title></title> <script
I have the following ASPX page: <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title></title> <script src=js/jquery-1.2.6.min.js
I have the following jquery in my ASP.NET regular pages <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <link type=text/css href=App_Themes/jquery-ui-1.7.3.custom.css rel=stylesheet /> <script
Here's my page: <html xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:cpanel=http://java.sun.com/jsf/composite/components/cpanel xmlns:f=http://java.sun.com/jsf/core xmlns:p=http://primefaces.prime.com.tr/ui xmlns:ui=http://java.sun.com/jsf/facelets> <h:head> <title></title> </h:head> <h:body>
In my .xhtml page, I have the following form: <ui:composition xmlns:ui=http://java.sun.com/jsf/facelets template=./../template/CustomerTemplate.xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:f=http://java.sun.com/jsf/core

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.