Welcome Guest, Not a member yet? Register   Sign In
Problem with drop down -- please help
#1

[eluser]theciman[/eluser]
Hopefully I am not wasting anyone time. I have been working on this problem for a while and can't seem to figure it out. Also I checked this forum and tried googling for an answer without any results. My question is hopefully simple.

I am able to query a database and put the results in a drop down using the form_dropdown helper. My problem is I just don't know how to have CI return the dropdown value. In other words if I have 10 items in my list and the user selects the 8th item, how do I retrieve the 8th item so I can do something with it. I am able to print it out the first time as a default but can't do it repeatedly.


Here is the code I am using:

Controller:

<?php

class Trmc extends Controller {

function Trmc()
{
parent::Controller();

$this->load->helper('form');

}

function index()
{
$data['title'] = "TRMC Database Update Function";
$data['heading'] = "TRMC Database Update Function";
$data['capability'] = "Capabilities";
// $data['capability_query'] = $this->db->query('SELECT * FROM Capabilities');
$data['capability_query'] = $this->db->get('Capabilities');

$data['challenge'] = "Challenges";
// $data['challenge_query'] = $this->db->query('SELECT * FROM Challenges');
$data['challenge_query'] = $this->db->get('Challenges');

$this->load->view('trmc_main_view', $data);



}
}

?>


View:

<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
<h2>&lt;?php echo $heading ?&gt;</h2>

<h4>&lt;?php echo $capability ?&gt;</h4>
&lt;?php
if ($capability_query->num_rows() > 0)
{
// $incr=0;
$selected = '';
foreach($capability_query->result() as $row)
{
$results[$row->CapabilityID] = $row->CapabilityDesc;
$resultsID[$row->CapabilityID] = $row->CapabilityID;
$incr++;
}
echo form_dropdown('Capabilities',$results,'');
$capselectID = form_dropdown('Capabilities',$resultsID, '0');

//This displays the default correctly once duringthe load but that's it!
if(form_dropdown('Capabilities',$results, 'Unknown'))
echo "Unknown";
else if (form_dropdown('Capabilities',$results, 'Another Selection'))
echo "Another Selection";





}
?&gt;

<h4>&lt;?php echo $challenge ?&gt;</h4>
&lt;?php
if ($challenge_query->num_rows() > 0) // alternate method for populating drop down
{
$incr=0;
foreach($challenge_query->result() as $row)
{
$results[$incr] = $row->ChallengeDesc;
$incr++;
}
echo form_dropdown('Challenges',$results,'Unknown');
}
?&gt;



&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]AndresC[/eluser]
I can't find the open form tag, so when you submit the form it sends you variables to the controller. You can use form_open helper or &lt;form .... html tag.
#3

[eluser]theciman[/eluser]
Thanks, I'll look into that.
#4

[eluser]theciman[/eluser]
Is there a way I can use some sort of callback or event to return the dropdown selection without refreshing the page. I want the user to select a dropdown value and a soon as they do it I need away to retrieve it with a page refresh or a button submit. Any help would be appreciated.
#5

[eluser]Aidy[/eluser]
You can use the onchange as described here

http://www.htmlcodetutorial.com/forms/_T...hange.html

Maybe with a function like this

Code:
function sub_drop()
{
    with (window.document.your_form) {
        [removed].href = '&lt;?=site_url('your_page')?&gt;/' + your_drop.options[your_drop.selectedIndex].value;
    }
}

The [removed] bit is window[dot]location

Of course this cannot be relyed on as its javascript as the link says.
#6

[eluser]danmontgomery[/eluser]
You can use onchange() to call javascript when the select value changes.

http://www.google.com/search?q=javascrip...n+onchange




Theme © iAndrew 2016 - Forum software by © MyBB