CodeIgniter Forums
How To Get Departments Based on Course - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How To Get Departments Based on Course (/thread-49370.html)



How To Get Departments Based on Course - El Forum - 02-17-2012

[eluser]prakash[/eluser]
Hi iam using ci form tags to design a form.....
Here i want to get departments based on the course selected so how to move on
Here is my code
---------------------------------------
<tr class="fieldbox">
<td width="311" align="right" height="23">
&lt;?php echo form_label('Courses','course'); ?&gt;</td>
<td width="33"> <strong>:</strong> </td>
<td width="431" colspan="2">&lt;?php
$course = $this->db->query("select * from courses");
foreach($course->result() as $courses)
{
$coursenames[]= $courses->course_name;
}

echo form_dropdown('Courses', $coursenames, 'course');?&gt; </td>
</tr>

<tr class="fieldbox">
<td width="311" align="right" height="23">&lt;?php echo form_label('Department','dept'); ?&gt; </td>
<td width="33"> <strong>:</strong> </td>
<td width="431" colspan="2">&lt;?php
$dept = $this->db->query("select * from departments");
foreach($dept->result() as $depts)
{
$ddata[]= $depts->dept_name;
}

echo form_dropdown('departments', $ddata, 'dept');?&gt; </td>
</tr>


How To Get Departments Based on Course - El Forum - 02-17-2012

[eluser]aquary[/eluser]
How is the code doing now? what are the errors? please be more specific Smile

btw, please use code tag for any coding...


How To Get Departments Based on Course - El Forum - 02-17-2012

[eluser]prakash[/eluser]
Everything is working fine

In my form it should display all the departments in a drow down list when i select an particular course in drop down list

generally we use

onchange="document.frm.submit();


but for this ci form what we should write?

(eg: if we select country based on country it should display states in that particular country)

Code:
<tr class=“fieldbox”>
<td width=“311” align=“right” height=“23”>
&lt;?php echo form_label(‘Courses’,‘course’); ?&gt;</td>
      <td width=“33”> :      </td>    
    <td width=“431” colspan=“2”>&lt;?php
  $course = $this->db->query(“select * from courses”);
    foreach($course->result() as $courses)
  {
  $coursenames[]= $courses->course_name;
  }

    echo form_dropdown(‘Courses’, $coursenames, ‘course’);?&gt;      </td>
  </tr>

  <tr class=“fieldbox”>
  <td width=“311” align=“right” height=“23”>&lt;?php echo form_label(‘Department’,‘dept’); ?&gt;      </td>
      <td width=“33”> :      </td>    
    <td width=“431” colspan=“2”>&lt;?php
  $dept = $this->db->query(“select * from departments”);
    foreach($dept->result() as $depts)
  {
  $ddata[]= $depts->dept_name;
  }

    echo form_dropdown(‘departments’, $ddata, ‘dept’);?&gt;      </td>
  </tr>



How To Get Departments Based on Course - El Forum - 02-17-2012

[eluser]aquary[/eluser]
You can put onchange and anything other than name, value and data to the 4th parameters:

Code:
echo form_dropdown(‘departments’, $ddata, ‘dept’, 'onchange="do_something()"');



How To Get Departments Based on Course - El Forum - 02-17-2012

[eluser]InsiteFX[/eluser]
Click on FAST REPLY and it will show you how to use the code tags or better yet use the POST REPLY has full editor!



How To Get Departments Based on Course - El Forum - 02-19-2012

[eluser]prakash[/eluser]
Code:
echo form_dropdown('courses', $courses, 'course' , 'onChange="document.myform.submit();"');

My code is like that, its saying

document.myform.submit is not a function--- please help me out


also how to prefill selection box?

my code

Code:
<tr class="fieldbox">
  <td width="311" align="right" height="23">&lt;?php
        $attributes = array('id' => 'myform', 'name' => 'myform' , 'method' => 'post');
  echo form_open('rsis/scholarsubmit' , $attributes);
  $options = array(
      'Select'  => 'Select',
                  'Mr'  => 'Mr',
                  'Mrs'    => 'Mrs',
                  'Ms'   => 'Ms',
                  );
      echo form_label('Salutation','sal'); ?&gt;        </td>
        <td width="33"> <strong>:</strong>        </td>          
    <td width="431" colspan="2">&lt;?php
    $res = str_replace("'","",$departments[0]->salutation);
    echo form_dropdown('salutations', $options, 'sal', set_value($res));?&gt;        </td>
  </tr>



How To Get Departments Based on Course - El Forum - 02-20-2012

[eluser]aquary[/eluser]
I think it's the 3rd parameter telling what is the current selected value.

As for the javascript error, I'm not sure since I've not used pure native javascript for quite a while. Check you generated HTML sourcecode if the form tag missed something required for document.myform.submit() to work.