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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:48:50+00:00 2026-06-18T18:48:50+00:00

I’m having trouble getting my variable to post in my form. I use jquery

  • 0

I’m having trouble getting my variable to post in my form. I use jquery to load a box if the user wants to enter a new sub category.

Here is the select in the form

<select id="sub_cat1" name="sub_cat1">
   <option value=""></option>
   <option value="new">New Sub Cat</option>
<?php
$query = "SELECT sub_category FROM blog_posts GROUP BY sub_category";
$data = mysqli_query($dbc, $query);
    if (mysqli_num_rows($data) > 0) {
      while ($row = mysqli_fetch_array($data)) {
    $sub_category = $row['sub_category'];
    echo '<option value="' . $sub_category . '">' . $sub_category . '</option>';
    }
     }
?>
        </select>
<div id="load_sub_cat_box"></div>

This is the jquery

$(document).ready(function(){ 
$("#sub_cat1").on("keyup change", function() {  
  var prod = $("#sub_cat1").val();
  if(prod == 'new'){
  $("#load_sub_cat_box").append('<div style="padding-top:15px;">Enter New Sub Category</div><input type="text" name="sub_cat2" />');
  }
    }); 
});

And here is the form validate code

  if($_POST['sub_cat1'] == "new"){
$sub_cat = mysqli_real_escape_string($dbc, trim($_POST['sub_cat2']));
  }
  else{
$sub_cat = mysqli_real_escape_string($dbc, trim($_POST['sub_cat1']));  
  }

If I select new, the box does load on the page but for some reason when form is submitted it will not load a variable for $sub_cat1. Is there something I don’t know about jquery and forms?

  • 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-18T18:48:52+00:00Added an answer on June 18, 2026 at 6:48 pm

    You have two select elements with id=”sub_cat1″.

    ids must be unique per page.

    It is also invalid HTML, with a select inside a select.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.