• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Get Departments Based on Course

#1
[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>

#2
[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...

#3
[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>

#4
[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()"');

#5
[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!

#6
[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>

#7
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.