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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:36:07+00:00 2026-06-08T14:36:07+00:00

I am currently working with AJAX/JS to auto submit form. The function works well

  • 0

I am currently working with AJAX/JS to auto submit form. The function works well with text input fields but with a select box is not working well. Is there a way to get the JS function to echo the value of the selected item? EXAMPLE

AJAX/JS submit function

<script>
     $(document).ready(function() {
         var timer = null; 
         var dataString;   
         function submitForm(){
           $.ajax({ type: "POST",
                    url: "test1.php",
                    data: dataString,
                    success: function(result){

                    $('#condition_input').text( $('#resultval', result).html()); 

                    }

           });
           return false;
         }

         $('#condition').on('keyup', function() {
            clearTimeout(timer);
            timer = setTimeout(submitForm, 1000);
                  var condition = $("#condition").val();
            dataString = 'condition='+ condition;
            });
     });
    </script>

Html/PHP

if (isset($_POST['condition'])){
    $condition = $_POST['condition'];   
    echo ('<div id="condition"><span id="resultval"><h2>Description:</h2>'.$condition.'</span></div>');
}

    <select name="condition" id="condition" value="<? $condition ?>" >
        <option value=""></option>
            <option value="new">New</option>
        <option value="used">Used</option>
        <option value="not Working">Not Working or for parts</option>
    </select>
  • 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-06-08T14:36:09+00:00Added an answer on June 8, 2026 at 2:36 pm

    You have to bind the “on change”-event:

    $('#condition').on('keyup change', function() {
      // ...
    }
    

    And your markup is not correct. You can not set a value attribute on select element. To select the correct value you have to loop over the options and mark the correct one by setting the attribute “selected”:

    <?php
    
    // ...
    
    $options = array(
      '' => '', 
      'new' => 'New',
      'used' => 'Used',
      'not_working' => 'Not Working or for parts',
    );
    ?>
    
    <select name="condition" id="condition" >
    <?php foreach ($options as $optionValue => $optionText): ?>
        <option value="<?php echo $optionValue ?>" <?php echo $condition == $optionValue ? 'selected="selected"' : null ?>><?php echo $optionText ?></option>
    <?php endforeach ?>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a jQueryMobile application with some form fields that need auto complete
I'm currently working on an AJAX file upload script, which works like a charm
I am currently working with AJAX/JS to have form without a button click or
I am currently working with a JS/AJAX functions that works without a page refresh
I am currently working on some Ajax heavy code and I am wondering how
I am currently working on a ASP.NET AJAX application. Having decided to not use
I am working on a AJAX/jquery notification script. Currently it retunrs a whole fhtml
I'm currently working on a project involving a form generator. The user can switch
I'm currently working with the AJAX:UpdatePanelAnimationExtender and I've implemented it in code behind which
I'm currently working on a page which makes use of the MS Ajax UpdatePanel.

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.