Jump to content

Problem with parsing variable to form


herghost

Recommended Posts

First, apologies if this is in the wrong section, basically I am not sure what language my problem lies!

 

Here is the general over view.

 

I have a jquery script that automatically selects a group of sub categorys and pus them in a select list depending on the input of a first select list, so you can choose you main cat and then the sub cats for this cat appear in the next list, this all works fine, the basic code is below:

<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
  $('#wait_1').show();
  $('#result_1').hide();
      $.get("scripts/func.php", {
	func: "drop_1",
	drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
    	return false;
});
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>
<form action='do.php' method='post'>
<select name="drop_1" id="drop_1">
                <option value="" selected="selected" disabled="disabled">Select a Category</option>
                <?php getTierOne(); ?>
                </select> 
                 <span id="wait_1" style="display: none;">
                 <img alt="Please Wait" src="images/ajax-loader.gif"/>
                 </span>
                 <span id="result_1" style="display: none;"></span>

 

This calls scripts/func.php

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT * FROM blog_cats") 
or die(mysql_error());

  while($tier = mysql_fetch_array( $result )) 
  
	{
	   echo '<option value="'.$tier['cat_id'].'">'.$tier['cat_name'].'</option>';
	}

}

//**************************************
//     First selection results     //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

function drop_1($drop_var)
{  
    include_once('../connect.php');
$result = mysql_query("SELECT * FROM blog_subs WHERE cat_id='$drop_var'") 
or die(mysql_error());

echo '<select name="tier_two" id="tier_two">
      <option value=" " disabled="disabled" selected="selected">Select Sub Catergory</option>';

	   while($drop_2 = mysql_fetch_array( $result )) 
		{
		  echo '<option value="'.$drop_2['sub_id'].'">'.$drop_2['sub_name'].'</option>';
		}

echo '</select> ';
    
}
?>

 

 

The problem I am having is getting the second select (tier_two) to pass to my form processing page.

 

I just get an undefined variable error

 

Many Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/234506-problem-with-parsing-variable-to-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.