Welcome Guest, Not a member yet? Register   Sign In
need some input
#1

[eluser]madkris[/eluser]
Hi,

I'd like to be able to select from a drop down list and each time i make a selection a link which says something like "select another" appears on its side and when i click that link the drop down list appears again kinda like how you attach files on yahoomail.Any idea how I do this? Is there an existing script which does something like this?

I tried searching but I am not sure what i should be looking for.

EDIT:initially there's one drop down list.
#2

[eluser]JWarren[/eluser]
You'd have to use javascript to add form elements to the DOM. Have you used any javascript frameworks? Jquery, etc?
#3

[eluser]xwero[/eluser]
this seems like a javascript deal. In pseudo co i would do something like this.

- php creates a select with the id selections
- javascript hides the select and shows the link : make selection, on the same place of the select
- clicking on the link makes javascript hide the link and show the select
- clicking on an option makes javascript store the selection in a hidden input, shows it somewhere, and goes to the original state of select and link
- use the hidden input to store the user selected values in php
#4

[eluser]madkris[/eluser]
Thanks,really helps when you know what you are really trying to find.Just trying to figure out why only the first selection gets stored on my db even thou i have made multiple selections.

Got another question,how to redirect the user to the page where he left after he successfully logged in after being redirected to login page due to expired session.If possible, i'd prefer being able to do this in CI.
#5

[eluser]JWarren[/eluser]
[quote author="madkris" date="1234313662"]Just trying to figure out why only the first selection gets stored on my db even thou i have made multiple selections.[/quote]

Make sure all of your select elements have different names. Then use foreach to loop through the POST data.

You may want to start a separate thread for other questions.
#6

[eluser]madkris[/eluser]
They have different names.Previous code prior to this script didn't need the loop but stored up to 15 selections.Will try the loop and see if it works.

Right,making a new thread now.Thanks for the tip.
#7

[eluser]xwero[/eluser]
If you do a multiple select the name of your select has to have square brackets at the end of its name. The same works if you have multiple inputs that have the same name.
Code:
<select name="select[]" multiple="multiple">


&lt;input type="hidden" name="hidden[]" value="1"&gt;
&lt;input type="hidden" name="hidden[]" value="2"&gt;
&lt;input type="hidden" name="hidden[]" value="3"&gt;
#8

[eluser]madkris[/eluser]
here's the modified script(note: i left some of the variables as they are to avoid confusion) of an example i got from the net:

Code:
var iterator = 1;
            var uplTemplate = new Template('<div id="element-templates"><br><div id="#{id}" class="row"><div class="form-dropbox">#{label}:&nbsp;<select name="#{name}">                <option value="">Select Contest Problem</option>&lt;?php    foreach($list->result_array() as $row){    echo "<option value=".$row['pcode'].">".$row['pcode']." -- ".$row['ptitle']."</option>";}?&gt;            </select></div></div></div>');

            function insertNewTemplate(){
            iterator++;
            Element.insert($('files'),uplTemplate.evaluate({'id':'file' + iterator, 'name':'problem' + iterator, 'label':iterator}));
            }

            $('add-file-upload').observe('click',insertNewTemplate);


here's where i insert them to the database.
Code:
foreach($query->result_array() as $row) {
                                $num = $row['contestid'];
                              }
                            $sql = "INSERT INTO contestproblems  
                                    VALUES ($num, '$problem1')";
                                $this->db->query($sql);
                            if($problem2 != NULL){
                                $sql = "INSERT INTO contestproblems  
                                            VALUES ($num, '$problem2')";
                                        $this->db->query($sql);
                            }
                            .
                            .
                            .
                            .
                            .      
                            if($problem15 != NULL){
                                $sql = "INSERT INTO contestproblems  
                                            VALUES ($num, '$problem15')";
                                        $this->db->query($sql);
                            }

not sure if making a loop will do the trick.
i know my code is very messy, do be gentle.. -.-
#9

[eluser]xwero[/eluser]
Instead of using the iterator to append a number to the name just use problem[] then you can do
Code:
$values = array();
foreach($problem as $temp)
{
   $values[] = "($num,$temp)";
}

if( ! empty($values))
{
   $sql = "INSERT INTO contestproblems (contest_id,problem) VALUES ".implode(',',$values);
   $this->db->query($sql);
}




Theme © iAndrew 2016 - Forum software by © MyBB