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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:37:17+00:00 2026-06-16T04:37:17+00:00

i am new to jquery, i have only recently discovered its amazing use so

  • 0

i am new to jquery, i have only recently discovered its amazing use so be easy on me please.

What i am trying to do is have an html input text box, have a variable instantly parse the input, and send that variable which contains the input text box string into a php switch statement through jquery.

The part from jquery to php works, but the part from transmitting a dynamic input text box into a variable for jquery doesn’t.

Here’s what i have:

  <script src="jquery-1.8.3.js"></script>
   <input id="in" type="text" onchange="myFunction()" />
   <script>
 function myFunction()
 {
  var a = document.getElementById("in");
  }
  // i am trying to make this var a equal to what is typed in the input box so that it can go into the "jsvar: a" part //
  $(document).ready(function(){

  $("button").click(function(){

  $.post("runphp.php", {  jsvar: a}, function(jsvar){ alert(jsvar);
     });
     });
     });
     </script>
     <button>Run php switch statement with input</button>

and the “runphp.php” file is simply a switch statement that works

  <?php 
   switch($_POST['jsvar'])
    {
     case "pass": 
      echo "<3"; break;
     case "other stuff":
     echo "</3"; break;
      default:
     echo ":("; 
     }
    ?>

The php part works fine.
But the thing is, if i declare, for example, var a = “pass” instead of doing onchange & myFunction(); then the jquery part works perfectly and passes on that value into jquery and into the php switch statement, yet when i try to make var a = that input box, it won’t go through to php. I tried making an onchange function, but it still won’t make var a equal to what i type in the input box so that it passes into the php switch statement through jquery.

  • 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-16T04:37:19+00:00Added an answer on June 16, 2026 at 4:37 am

    You are missing .value

    var a = document.getElementById("in").value;
    

    Second

    You are use jquery as below

    var a = $("#in").val();
    

    Change JS function as below

    $(document).ready(function(){
    
      $("button").click(function(){
    
      $.post("runphp.php", {  jsvar: $("#in").val()}, function(jsvar){ alert(jsvar);
         });
         });
         });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey people I'm new at jquery and i have been trying to figure this
I'm new to jQuery and I want to have a input box from a
I have only recently begun to play around with html, javascript, webapps etc and
I am somewhat new to jQuery but have been having fun trying learn about
I'm new to Jquery... I'm trying to have a simple system as shown below...
i'm new to jquery .I have problem in the following code .I saved it
I'm new to jQuery and have noticed someone go: var $this = $(this); Why
I am new to jQuery and have run into a problem. I have a
I am somewhat new to jQuery and I have a problem with something I
I have application that brings response via Ajax and creates 5-20 new jQuery click

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.