Welcome Guest, Not a member yet? Register   Sign In
javascript on dinamic generated form
#1

[eluser]pegas[/eluser]
Hy , here's one for you :
I have a controller in wich I place some variables from my model and then i render the view in which I make a form using form_open(I've used the method without using codeigniter to) and a foreach to generate some checkboxes.

then i have a javascript that "listenes" to what i check and gives me as feedbak(for the moment) a simple alert message.

The problem is that with generating the form this way my javascript returns nothing( it should return the name of the checked element for example) .

If the same form with de same name and same action( and etc) is made on brute HTML without using loops or php or codeigniter however , everything works just fine.

So this is my problem.
The asset helper is loaded , the form helper is loader , the code does not have errors.
Help me please.

Here is some code:
the function:
Code:
function get_check_value(){
   var c_value = "";
for (var i=0; i < document.promoForm.promo.length; i++)
   {
   if (document.promoForm.promo[i].checked)
      {
      c_value = c_value + document.promoForm.promo[i].value + "\n";
      }
   }
   alert(c_value);

}

the view :
Code:
&lt;html&gt;
&lt;head&gt;
&lt;?php echo css_asset('tabcontent.css')?&gt;
&lt;?php echo js_asset('tabcontent.js')?&gt;
&lt;?php echo js_asset("outils.js") ?&gt;
&lt;title&gt;Gestion du personnel(promo) a revoir&lt;/title&gt;

&lt;/head&gt;
&lt;body&gt;
<h2>Gestion de promotions </h2>
&lt;?php echo form_open('',$atributes)?&gt;

     &lt;?php echo '' ;
        foreach($promos as $id=>$value)
        echo $value.form_checkbox("promo", $value,true)."<br />" ;
        ?&gt;
      &lt;input type="button" id="creer_onglets" name="creer_onglets" value="Gerer"&gt;
&lt;?php echo form_close() ;?&gt;

&lt;!-- modified the name so the javascript works with the other form --&gt;
&lt;form name="promoForm_TEST"&gt;
    &lt;input type="checkbox" name="promo" value="X" checked="checked" /&gt;
     &lt;input type="checkbox" name="promo" value="Y" checked="checked" /&gt;
      &lt;input type="checkbox" name="promo" value="rze" checked="checked" /&gt;
      &lt;input type="button" id="creer_onglets" name="creer_onglets" value="Gerer"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

a part of he controller :
Code:
$this->load->helper('asset');
$this->load->helper('form');
$data['atributes'] = array('name'=>'promoForm');
$data['promos'] = $this->M->getTsPromos($dept);
$this->load->view('vue_gestionPerso',$data);
#2

[eluser]Aken[/eluser]
Compare your working HTML to the HTML generated by CodeIgniter, and see what's different. Seems simple enough.

I can tell you, though, that you shouldn't be generating a handful of checkboxes with the same name, as you can only have one value per name, so if multiple boxes are checked, only the last one will pass through the POST/GET.
#3

[eluser]pegas[/eluser]
Nothing is different :| ..
#4

[eluser]Aken[/eluser]
Something has got to be different, or they'd both work fine, hehe.




Theme © iAndrew 2016 - Forum software by © MyBB