This is a migrated thread and some comments may be shown as answers.

Post data into db from multiselect

4 Answers 98 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 05 Feb 2014, 01:24 PM
Hi!
I have 2 datasources: for multiselect and for dropdownlist, and 1 datasource for insert data into db from multiselect and dropdownlist.
But as result i have new record in database: id_client: blank and id_board: (needed value).
When i do "alert(required.value() + optional.value() )" i getting needed values. Why is blank posted data in field "id_client"?


 var required = $("#multiclients").data("kendoMultiSelect");<br>            var optional = $("#ddrecord").data("kendoDropDownList");<br><br><br>            $("#mrecord").click(function() {<br>             alert(required.value() + optional.value() );<br>         var dataa = {id_client: required.value(), id_board: optional.value()};<br>        dataSR.add(dataa);<br>         dataSR.sync();<br>  }); 

4 Answers, 1 is accepted

Sort by
0
Jack
Top achievements
Rank 1
answered on 05 Feb 2014, 02:42 PM
If i do 
var dataa = {id_client: 77, id_board: 99}
data posted normally.
0
Alexander Popov
Telerik team
answered on 07 Feb 2014, 09:52 AM
Hello Jack,

Thank you for the code snippet. I noticed that in the working example a numeric value was passed. The MultiSelect's value method however, returns an array of strings which may not be recognized by the controller.
In case the above does not answer your question I would ask you provide additional information, so we can advise you further.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jack
Top achievements
Rank 1
answered on 07 Feb 2014, 11:18 AM
My goal is  record 1 or more clients to fitness training.

What i need and what i have: 
i have multiselect with datasource (data from mysql table "clients"),
i have dropdownlist with datasource (data from mysql table "board" (trainings)).
I need to choose 1 or more clients and 1 training and put their id's into mysql table "record"(att. file).
The result 1 or more new records in table "record".
0
Jack
Top achievements
Rank 1
answered on 09 Feb 2014, 03:45 PM
Solved.

var required = $("#multiclients").data("kendoMultiSelect");
var optional = $("#ddrecord").data("kendoDropDownList");
var req = required.value();
 
 $("#mrecord").click(function() {
 
 var dataa = {"id_client": req, "id_board": optional.value()};
dataSR.add(dataa);
dataSR.sync();
 
});

and php code:
case 'record':
             $columns = array('id_record', 'id_client', 'id_board');
             switch($type) {
                   case 'create':
                           require_once 'db/DB_Functions.php';
                           $db = new DB_Functions();
                           $options = array();                      
                           $models = $request->models[0]->id_client;
                           $board = $request->models[0]->id_board;
                             foreach($models  as  $key => $value) {
                                         $options[] =  "(NULL, $value, $board)";  }
                           $options2 = implode(", ", $options);
                           $sql = "INSERT INTO `record` (`id_rec`, `id_client`, `id_board`) VALUES $options2";
                           $result = mysql_query($sql) or die(mysql_error());
                        //$result = $result->create('record', $columns, $request->models, 'id_record');
                   break;

Maybe it is a sh#tcode but it works, rewrite here if u want :)
Tags
MultiSelect
Asked by
Jack
Top achievements
Rank 1
Answers by
Jack
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or