0

Hi i have select box and submit button and depend on the submit i want to send the form result to ajax and retrieve the array result. Here is my php code:

   if($param['aktion'] == 'get-widget-news-edit')
    {        


        $html = '<form name="UserInformationForm" method="POST" >
                 <table id="news"> ';
                  if(($post['news'])==4){

                $sql=" SELECT DISTINCT ad_news_texte.headline, ad_news.datum_archiv
            FROM ad_news_texte
            INNER JOIN ad_news_oe ON ad_news_texte.news_id = ad_news_oe.id_ad_news
            INNER JOIN ad_news ON ad_news_oe.id_ad_news = ad_news.id
            WHERE ad_news.datum_archiv
            BETWEEN curdate( ) - INTERVAL DAYOFWEEK( curdate( ) ) +28
            DAY AND curdate( )
            ";

                $sql_select=mysql_query($sql);
                while($row = mysql_fetch_array($sql_select)) {
                    echo $row['headline'] . " " .$row['datum_archiv'] ;
                    echo "<br>";
                }
            }

$html .= '<select name="news" id="news">
          <option value="4" '. (($_POST['news']=="4")  ?  "selected=selected" : "" ) .'>Show news from last 4 weeks</option>
           </select>                    
           </table>
           '.CreateButton($page['button']).'
           </form> 
          <div class="form_result"> </div>';

        $return = array(
                'status' => 1,
                'html'  => $html
            );

        echo json_encode($return);
        die();
    }

Js code to send the select box array result to ajax but unable to do that..

function saveNewsWidget()
    {
        var selectBoxValue = $('#UserInformationForm').find('.form_result').html();
        $.ajax({
        type: "POST",
        url: "ajax/dashboard.php",
        dataType : 'json',
        cache: false,
        data: {'aktion' : 'save-widget-news', 'news' : selectBoxValue },
        success: function(data)
        {
            //$('#news').html(data.html);
            getNewsWidget();
            //getNewsWidget();
            $('#news').html(data['html']);      
        }
      });
  }
user3702602
  • 139
  • 3
  • 16
  • update your code as bellow and let me know! I have used `val()` instead of `html()`. `var selectBoxValue = $('#UserInformationForm').find('.form_result').val()` – Milan V. Jun 25 '14 at 13:33
  • no nothing is passing ... – user3702602 Jun 25 '14 at 13:37
  • ok try `var selectBoxValue = $('#news').val();` sorry about previous comment – Milan V. Jun 25 '14 at 13:56
  • no not passing still...:( – user3702602 Jun 25 '14 at 13:58
  • Where is $`page['button']` set, and the code for `CreateButton()`? How is the function `saveNewsWidget()` called? Are you sure it is called? What PHP errors are you getting, and what errors appear in the console? – Matthew Johnson Jun 25 '14 at 15:00
  • $page['button'] is a button which is predefined structure of my project.And yes it is called.saveNewsWidget() allows to send result of my php code select box result. When i check in the firebug its not passing anything of my select box results ... – user3702602 Jun 25 '14 at 15:12
  • The button is just to call function not depend on my select box results.. – user3702602 Jun 25 '14 at 15:14
  • does anyone know the solution ? – user3702602 Jun 26 '14 at 11:21
  • Can you see the request you send to "ajax/dashboard.php"? Are there the parameters you expect? (if you're in Firefox, use the "Parameters" view of the Network tab) – Simone Jun 26 '14 at 12:27
  • yes i checked when i try to alert the value it saying undefined and passing it as a parameter for e.g i alert like this: var selectBoxValue = $('#UserInformationForm').find('.form_result').val; alert (selectBoxValue); – user3702602 Jun 26 '14 at 12:31
  • I think you have a typo in that last bit of code. You're getting `.val` instead of `.val()`. Try changing it to `var selectBoxValue = $('#UserInformationForm').find('.form_result').val(); alert (selectBoxValue);` and see if the value's alerted out. – jkrehm Jun 27 '14 at 20:07

0 Answers0