Problem with drop down -- please help |
[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><?php echo $heading ?></h2> <h4><?php echo $capability ?></h4> <?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"; } ?> <h4><?php echo $challenge ?></h4> <?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'); } ?> </body> </html>
[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 <form .... html tag.
[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.
[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() Of course this cannot be relyed on as its javascript as the link says.
[eluser]danmontgomery[/eluser]
You can use onchange() to call javascript when the select value changes. http://www.google.com/search?q=javascrip...n+onchange |
Welcome Guest, Not a member yet? Register Sign In |