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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.