I need your help. I have a problem with dropdown value. I can't save value from dropdown list,which has appeared.
I did everything like this example, but I have appearing , not . And the problem is - I cant save value I chosen. I need this value for insert into my database.What must I change here?
[http://jsfiddle.net/Bksk7/2/]
myview.php
<script>
$(function() {
$(".forms").hide();
$("#type").change(function()
{
var e = $(this).val();
if(e == 1 || e == 2) //for example, I have 2 another dropdown
{
$(".forms").hide().parent().find('#' + e).show();
}
});
$('#submit').click(function(e)
{
e.preventDefault();
var resolve_data = function() {
var output = {};
$('.form-active select, .default select').each(function()
{
output[$(this).attr('value')] = $(this).val();
});
return output;
};
});
});
</script>
<form action="http:/../insertdata" method="post">
<table class="main">
...
<select name="type" id="type"> //it works clear__ dropdown #1
<?php
$selected_1 = 'selected="selected"';
$selected_2 = '';
foreach ($types as $item)
{
$id=$item['type_id'];
$selected = $selected_2;
if (isset($_POST['type']) && $_POST['type'] == $id)
$selected = $selected_1;
echo '<option value="'.$id.'" ' . $selected . '>'.$item['title'].'</option>';
}
?>
</select>
....
<tr class="forms" id="1">
<td>
Введите категорию:
</td>
<td>
<select name="kategory" > //___dropdown #2
<?php
$selected_1 = 'selected="selected"';
$selected_2 = '';
foreach ($categories1 as $item)
{
$id=$item['id'];
$selected = $selected_2;
if (isset($_POST['kategory']) && $_POST['kategory'] == $id)
$selected = $selected_1;
echo '<option value="'.$id.'" ' . $selected . '>'.$item['title'].'</option>';
}
?>
</select>
</td>
</tr>
//and another the same
<tr class="forms" id="2">
<td>
Введите категорию:
</td>
<td>
<select name="kategory" > //__dropdown #3
<?php
$selected_1 = 'selected="selected"';
$selected_2 = '';
foreach ($categories2 as $item)
{
$id=$item['id'];
$selected = $selected_2;
if (isset($_POST['kategory']) && $_POST['kategory'] == $id)
$selected = $selected_1;
echo '<option value="'.$id.'" ' . $selected . '>'.$item['title'].'</option>';
}
?>
</select>
</td>
</tr>
....
<input type="submit" id="submit" "name="add" value="Добавить" />
</form>
controller insertdata.php
....
//I do this for values from dropdown #2 and #3
$add['categories1']=$this->ych_material_model->get_categories('programmnie');
$add['categories2']=$this->ych_material_model->get_categories('teoreticheskie');
And thats all right, but when I call .... $add['kategory']=$this->input->post('kategory');
in controller, it give me '1'.