Welcome Guest, Not a member yet? Register   Sign In
Load first value in select-box automatically
#1

[eluser]haily_php[/eluser]
I have done well to show data from second select box through first select-box; but i have one problem. First, if i chosen the first value, ( in second select-box) program would have not run; it would run from other values. Then, I chosen first value again, it run normally
How will I do to get the first value and to show data in second select-box automatically when I'll run program first

-- First Select-box ---
Quote:<select name="sub2_mainmenu" id="sub2_mainmenu">
&lt;?php

foreach($info as $item){
?&gt;
<option value="&lt;?php echo $item['idmainmenu'];?&gt;">&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php } ?&gt;
</select>

--Javascript--
Quote:[removed]
$('#sub2_mainmenu').change(function() {

var form_data = {
sub2_mainmenu: $("#sub2_mainmenu").val(),
};

$.ajax({
url: "&lt;?=site_url("index.php/menu/menu2/process/");?&gt;", // controller: menu2; action: process
type: 'POST',
data: form_data,
success: function(msg) {
$('#submenu').html(msg);
}
});
});


[removed]

-- Second Select-box --
Quote:<select name="sub2_mainmenu" id="sub2_mainmenu">
&lt;?php
if($info){
foreach($info as $item){
?&gt;
<option value="&lt;?php echo $item['idsubmenu'];?&gt;">&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php }}else{
echo "<option value='A'>Updating data...</option>";
}
?&gt;
</select>
#2

[eluser]toopay[/eluser]
put 'selected' on option tags
Code:
// ... the rest of your code
&lt;?php
if($info)
{
   $i = 0;
   foreach($info as $item)
   {      
      if($i == 0)
      {
?&gt;
      <option value="&lt;?php echo $item['idsubmenu'];?&gt;" selected >&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php
      }
      else
      {
?&gt;
      <option value="&lt;?php echo $item['idsubmenu'];?&gt;">&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php
      }
      $i++;
   }
}
else
{
// ... the rest of your code
#3

[eluser]haily_php[/eluser]
[quote author="toopay" date="1305223454"]put 'selected' on option tags
Code:
// ... the rest of your code
&lt;?php
if($info)
{
   $i = 0;
   foreach($info as $item)
   {      
      if($i == 0)
      {
?&gt;
      <option value="&lt;?php echo $item['idsubmenu'];?&gt;" selected >&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php
      }
      else
      {
?&gt;
      <option value="&lt;?php echo $item['idsubmenu'];?&gt;">&lt;?php echo $item['tieude'];?&gt;</option>
&lt;?php
      }
      $i++;
   }
}
else
{
// ... the rest of your code
[/quote]

Thank for helping but your way has not run
#4

[eluser]toopay[/eluser]
I've just notice that you have same name and id property at different select box. Thats seems can be a problem.
#5

[eluser]haily_php[/eluser]
First, I have also thought same your mean ( same name an id property at second select-box). But it has not run? I don't know why?




Theme © iAndrew 2016 - Forum software by © MyBB