Welcome Guest, Not a member yet? Register   Sign In
on drop down selection
#1

[eluser]diasansley[/eluser]
below is my view code i wanted to add a script that directly takes the select value when u select an option from the drop down without using the submit button.



Code:
<li class="brands_dropdown">
        <h4 class="h4">Marken</h4>
        &lt;?= form_open('entries/showAllEntries');?&gt;
            <select name="brands" id="brands" class="lisbox">
                <option value="0">--Select--</option>  
                &lt;?php
                      foreach($brands as $brand):
                          if(isset($type) && $type == 'brand')
                             $selected = ($brand['id']==$type_id)? 'selected = "selected"' : '';
                          else
                              $selected='';
                 ?&gt;        
                    <option  value="&lt;?=$brand['id'];?&gt;" &lt;?=$selected;?&gt;>&lt;?=$brand['name']?&gt;</option>  
                &lt;?php endforeach;?&gt;    
             </select>
             &lt;input type="hidden" value="brand" id="entry_type0" name="entry_type" /&gt;
             &lt;input type="submit" value="Submit" /&gt;
             &lt;?=anchor('brands/showAllBrands', 'alle Marken', array('id'=>'all_brands_link'));?&gt;
         &lt;?= form_close();?&gt;
    </li>


thanks rgds
#2

[eluser]LuckyFella73[/eluser]
Code:
<scr+ipt type="text/javascript">
function dropdown_submit(form)
{
    var index=form.select.selectedIndex
    if (form.select.options[index].value != "0")
    {
        //  document.forms["myform"].submit(); // edit for your needs!
    }
}
</scr+ipt>
Code:
<select name="select" on+change="dropdown_submit(this.form)" size="1"> // remove '+' of course
#3

[eluser]diasansley[/eluser]
i have added a [removed] but the function keyword is not getting highlighted in Pseditor.. any ideas. and also no action is performed. even after including the script.



Thanks Rgds
#4

[eluser]LuckyFella73[/eluser]
Hard to say whats going wrong without seeing your code.
Please post js part and HTML part with your select element.
#5

[eluser]diasansley[/eluser]
there is no action taking place.and also hoe do i send the data for processing in absence of a submit button.


Code:
<select name="entries" id="entries" class="lisbox">
     &lt; script type="text/javascript"&gt;
    function subsubmit(form)
   {
      var index=form.select.selectedIndex
      if (form.select.options[index].value != "0")
      {
        
        }
   }
      [removed]
                <option value="0">--Select-- </option>    
                
       &lt;?php foreach($entries as $entry):?&gt;        
                        <option  value="&lt;?=$entry['id'];?&gt;">&lt;?= $entry['name']?&gt;</option>  
                 &lt;?php endforeach;?&gt;    
            </select>
            <noscript>
            &lt;input type="submit" value="Submit" /&gt;    
            </noscript>
            &lt;?=anchor('entries/showAllEntries', 'alle Mieter', array('id' => 'all_entries_link'));?&gt;
        &lt;?= form_close();?&gt;

    </li>
#6

[eluser]diasansley[/eluser]
ok i have made the foll changes included a js file but still no action is performed.
I have included my script at the end.

Code:
<li class="entry_dropdown">
        <h4 class="h4">Mieter</h4>
        &lt;?= form_open('entries/showEntryDetail');?&gt;
        
      
<select name="entries" id="entries" class="lisbox">
    
                <option value="0">--Select-- </option>    
       &lt; script type="text/javascript" src="C:\xampp\htdocs\front_end\load.js" &gt;        
       &lt;?php foreach($entries as $entry):?&gt;        
                        <option  value="&lt;?=$entry['id'];?&gt;">&lt;?= $entry['name']?&gt;</option>  
                 &lt;?php endforeach;?&gt;    
            </select>
            <noscript>
            &lt;input type="submit" value="Submit" /&gt;    
            </noscript>
            &lt;?=anchor('entries/showAllEntries', 'alle Mieter', array('id' => 'all_entries_link'));?&gt;
        &lt;?= form_close();?&gt;

    </li>

Code:
&lt; script type="text/javascript"&gt;
function dropdown_submit(form)
{
    var index=form.select.selectedIndex
    if (form.select.options[index].value != "0")
    {
         &lt;?=anchor('entries/showAllEntries',array('id' => 'all_entries_link'));?&gt;
    }
}
< /script>
#7

[eluser]LuckyFella73[/eluser]
I set up a complete example - you just have to adjust some code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html &gt;
    &lt;head&gt;

    &lt;title&gt;Form&lt;/title&gt;

    <scr++ipt type="text/javascript">
    function sub_submit(data)
    {
        if (data != "0")
        {
            document.forms["myform"].submit();
        }
    }
    </scr++ipt>

&lt;/head&gt;

&lt;body&gt;
<h4 class="h4">Marken</h4>
&lt;form id="myform" name="myform" action="showsubmitted.php" method="post"&gt;

    <select name="brands" id="brands" on++change="sub_submit(this.options[this.selectedIndex].value)">
        <option value="0">--Select--</option>
        <option value="1">1</option>    
        <option value="2">2</option>
        <option value="3">3</option>
    </select>

     &lt;input type="hidden" value="brand" id="entry_type0" name="entry_type" /&gt;
     &lt;input type="submit" value="Submit" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Just replace the "++", the form open and tag your select loop block.
I didn't want to set up controller to test so I did a pure html version.
#8

[eluser]diasansley[/eluser]
ok thanks a lot... it helped.




Theme © iAndrew 2016 - Forum software by © MyBB