1 Replies - 1057 Views - Last Post: 20 May 2011 - 08:21 AM

#1 danrevah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-May 11

Problem in submit form after loading it with Ajax

Posted 20 May 2011 - 07:21 AM

My code is getting a part of HTML form (select type)
but when ever I try to submit the form I've perviously recived it doesnt get the
dropdown list value...
why can't I get the dropdown list value?

this is what im doing when im trying to "catch" the POST:
PHP Code:
if (isset($_POST['cat'.$arr['id']]))
{
    $cat = secure($_POST['cat'.$arr['id']]);
    if ($cat !== "")
        mysql_query("INSERT INTO jobinfo (user_id,content, cat_id, catlist_id) VALUES ('".$uid."','','".$arr['id']."','".$cat."')");
}


this is my code on the main PHP file:
PHP Code:
echo '<div id="result'.$arr['id'].'">';
echo '<select name="cat'.$arr['id'].'" id = "cat'.$arr['id'].'" style="width:180px;">';
echo '<option value="">- '.$arr['category'].' -</option>';
$select_cat = mysql_query("SELECT * FROM searchcatslist WHERE cat_id='".$arr['id']."'");
while ( $arr_cat = mysql_fetch_array($select_cat) )
{
    echo '<option value="'.$arr_cat['id'].'">'.$arr_cat['category'].'</option>';
}
echo '</select>';
echo '</div>';
if ($arr['sortby'] > 0)
{
    echo '<script>
    $("#cat'.$arr['sortby'].'").live("click", function(event){            
    $("#cat'.$arr['sortby'].'").change(function () {
    var values = $("#cat'.$arr['sortby'].'").val();
';
echo '$.post("ajax_dlists.php", { id: values, count: "'.$arr['tafpos'].'", multiple: "not" },';
echo 'function(data){
$("#result'.$arr['id'].'").empty();
$( "#result'.$arr['id'].'" ).html(data);
});
});
});
</script>';
}


The ajax_dlists.php (this is the dropdown list I load):
PHP Code:
$sel = mysql_query ("SELECT * FROM searchcats WHERE tafpos='".$count."'");
        if ( $arr = mysql_fetch_array($sel) )
        {
            if ($multiple == "not")
                echo '<select id="cat'.$arr['id'].'" name="cat'.$arr['id'].'" style="width:180px; float: left;">';
            else
                echo '<select id="cat'.$arr['id'].'" name="cat'.$arr['id'].'" style="width:150px; float: left;">';
                
            echo '<option value="">- '.$arr['category'].' -</option>';
            
            
            $query = "SELECT * FROM searchcatslist WHERE sortby = '".$id."' OR ( sortby = '0' AND cat_id='".$arr['id']."' )";
            $result = mysql_query($query);
            
            while ($row = mysql_fetch_array($result))
            {
                echo '<option value="'.$row['id'].'">'.$row['category'].'</option>';
            }
            echo '</select>';


This post has been edited by danrevah: 20 May 2011 - 07:23 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem in submit form after loading it with Ajax

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Problem in submit form after loading it with Ajax

Posted 20 May 2011 - 08:21 AM

Hi,

If I am understanding you correctly you are trying to make your select dropdown populate dynamically via AJAX using $.post.

One thing I see is your ajax_dlists.php file references a $arr variable that does not seem to be present in the script, or at least not shown in the code you provided, that could cause problems.

I suggest that if you haven't already install a web dev tool like FireBug and use the console to see what is being sent and returned during AJAX calls.

I also highly suggest you look into code separation. In your files you are echoing out html,CSS,and Javascript this can make your code extremely hard to read, maintain, and debug.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1