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

  • Home
  • SEARCH
  • 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 9163189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:23:10+00:00 2026-06-17T14:23:10+00:00

I have a page that has 2 cascading Select using Ajax. The Ajax correctly

  • 0

I have a page that has 2 cascading Select using Ajax. The Ajax correctly populates the second Select, however when I go to post the data to MySQL using PHP i get an error that the field populated by AJAX is “Unidentified.” The exact error is

Notice: Undefined index: probcode in ..\input.php on line
21

It does post if the Ajax call is not made and the default select is still there. It only errors after AJAX has replaced the DIV.

I would like to add that it is like the from element disappears from PHP even though AJAX adds it to the form. Is there another PHP function I should use to post AJAX data to MySQL?

I do not know Jquery and am looking for a way to get this to work with just JavaScript at the moment (because of time and my lack of Jquery knowledge), however if there is an easy way to add Jquery to the existing code I would definitely be interested. Also i know the data is not secure going into MySQL at the moment, That will be addressed immediately after this. I am just working on a wire-frame of a specific function at the moment.

First the two selects.

            <tr>
                <td>Problem Type</td>
                <td><?php
                    mysql_connect("localhost", "root", "") or die("Connection Failed");
                    mysql_select_db("test")or die("Connection Failed");
                    $query = "SELECT * FROM wfprobtype ORDER BY probtype ASC";
                    $result = mysql_query($query);
                    ?>
                    <select name="probtype" id="probtype" onchange="changeContent(this.value)">
                    <?php
                    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                    ?>
                    <option value="<?php echo $line['ID'];?>" > <?php echo $line['probtype'];?> </option>
                    <?php
                    } 
                    mysql_close()
                    ?>
                    </select>
                </td>
                <td>Problem: </td>
                <td>
                    <div id="val2div">
                        <select name="probcode" id="probcode">
                            <option value="default"></option>
                        </select>
                    </div>
                </td>
            </tr>

This is what the Ajax calls to replace “val2div” val2.php

<?php
$val2=intval($_GET['val2']);
mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("test")or die("Connection Failed");
$query = "SELECT * FROM wfprobcode WHERE typeID='$val2' ORDER BY Probcode ASC";
$result = mysql_query($query);
?>
<select name="probcode" id="probcode"  onchange="">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['Probcode'];?>"> <?php echo $line['Probcode'];?> </option>
<?php
}
mysql_close()
?>

Ajax Script Dny.js

function changeContent(val)
{
if (val=="")
  // if blank, we'll set our innerHTML to be blank.
  {
  document.getElementById("val2div").innerHTML="";
  return;
  }
if (window.XMLHttpRequest) // new browser
  {  
      xmlhttp=new XMLHttpRequest(); // new browser
      alert("newb");
  }
else // Old Browser
  {  
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 

  }
  // on state change
  xmlhttp.onreadystatechange=function()
  {
  // if we get a good response from the webpage, display the output
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
      document.getElementById("val2div").innerHTML=xmlhttp.responseText;
  }
  }
 // GET file. 
xmlhttp.open("GET","val2.php?val2="+val, true);
xmlhttp.send();
 alert(val)
}

post to MySQL input.PHP

    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("test", $con);

    $sql="INSERT INTO `test`.`test` (
    `ID`,
    `Dattime`, 
    `probtype`,
    `probcode`
    )
    VALUES(
    NULL,NOW(),'$_POST[probtype]','$_POST[probcode]')";

    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }

mysql_close($con); ?> 

I am hoping I am just missing simple something at the moment. This is my first time working with Ajax. I really appreciate any and all help at the moment.

EDIT: – One final edit before I attempt to rewrite the whole thing. Is there a way that using Jquery I could fix this? If not does anyone have a down and dirty way to make it just full postback without the AJAX?

I really appreciate those that have contributed so far an anyone who has any ideas at all.

Thanks in Advance!

-D

  • 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-17T14:23:12+00:00Added an answer on June 17, 2026 at 2:23 pm

    After reviewing the code endlessly I have found that the everything works fine when using IE with the code above! The issues are directly with Firefox interpreting the AJAX return.

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

Sidebar

Related Questions

I have a page that has several ajax submission forms. Each form has a
I have a page that has an embedded iframe doing ajax requests.... when i
Using Woodwing, we have a page that has custom html in it, using the
I have a page that has several ListBox es that have some cascading filtering
I have a page that has multiple parts of the page loaded via ajax,
I have php page that has jquery ajax call. the begging of this page
I have a page that has multiple sliders (from http://www.switchonthecode.com/tutorials/using-jquery-slider-to-scroll-a-div ) and since each
I have a page that has a table list through AJAX pagination, all custom.
I have a page that has a form using this ajaxForm jQuery plugin .
I have a page that has various select elements. if i change a select

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.