Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/04/2009, 14:36
machoman112233
Invitado
 
Mensajes: n/a
Puntos:
De PHP a JavaScript

Buenas otra vez!!!

A ver saco unos datos de una Base De Datos (nombre, descripcion, etc), con algunos estos datos hago un <select> (con el nombre). Tengo un <textarea> donde muestro la descripcion de dicho nombre (al cambiar el valor del <textarea> me cambia la descripcion para lo nuevo elegido). Todo va bien mientras no introduzca en la descripcion ningun salto de linea, al hacerlo el javascript no recupera bien la informacio de la variable en php (solo de la cual esta el salto de linea)... Si hago un alert para ver le nombre o descripcion o ID ni siquiera aparece... no recoge nada...

Código javascript:
Ver original
  1. <div class="box">
  2.                 <fieldset>
  3.                     <legend><?php echo $lang['update_category']; ?></legend>
  4.                     <?php
  5.                     $sql = 'SELECT * FROM ' .$prefix. 'categories ORDER BY `id_categoria` DESC;';
  6.                     $query = $mysql_con->Consulta($sql);
  7.                     if($mysql_con->NumFilas() == 0)
  8.                     {
  9.                         echo '<b>' .$lang['query_zero'] .'</b>';
  10.                     }
  11.                     else
  12.                     {
  13.                     ?>
  14.                         <script type="text/javascript">
  15.                             var n = new Array(); //nombre ex: informatica
  16.                             var s = new Array(); //id: ex: 45DS45sz
  17.                             var d = new Array(); //descripcion: ex: programacion, harware, ofimatica, etc
  18.                             var ind = 0;
  19.                         </script>
  20.                         <?php
  21.                         while($data = $mysql_con->VerDatos($query))
  22.                         {
  23.                         ?>
  24.                             <script type="text/javascript">;               
  25.                                 n["<?PHP echo $data->sid_categoria; ?>"] = "<?PHP echo $data->nom; ?>";
  26.                                 d["<?PHP echo $data->sid_categoria; ?>"] = "<?PHP echo $data->descripcio; ?>";
  27.                                 s[ind] = "<?PHP echo $data->sid_categoria; ?>";
  28.                                 ind++;
  29.                             </script>
  30.                         <?php
  31.                         }
  32.                         ?>
  33.                         <script type="text/javascript">
  34.                         alert(s[0]);
  35.                         function show_select()
  36.                         {
  37.                             var i = 0;
  38.                             var se = document.getElementById("select");
  39.                             for(i = 0; i < s.length; i++)
  40.                             {
  41.                                 var o = document.createElement("option");
  42.                                 var t = document.createTextNode(n[s[i]].substr(0,50)+"...");
  43.                                        
  44.                                 o.setAttribute("onclick","(show_cat('"+s[i]+"'));");
  45.                                 o.appendChild(t);
  46.                                 se.appendChild(o);
  47.                             }
  48.                             show_cat(s[0]);
  49.                         }
  50.                        
  51.                         function show_cat(id)
  52.                         {
  53.                             document.getElementById("update_cat_name").value = n[id];
  54.                             document.getElementById("update_cat_desc").value = d[id];
  55.                             document.getElementById("cat_s").value = id;
  56.                         }              
  57.                         </script>
  58.                            
  59.                         <form action="<?php echo $root_path. 'functions/ctrlmysql.' .$phpEx; ?>" method="post" onsubmit="return(true);">
  60.                             <select id="select"></select><br />
  61.                             <p><?php echo $lang['category_name']; ?></p>
  62.                             <input type="text" id="update_cat_name" name="update_cat_name" size="30"/><br />
  63.                             <p><?php echo $lang['category_description']; ?></p>
  64.                             <textarea id="update_cat_desc" name="update_cat_desc" rows="5" cols="50"></textarea>
  65.                             <input type="hidden" name="cat_s" id="cat_s" value=""/><br />
  66.                             <input type="hidden" name="table" value="<?php echo 'categories'; ?>" />
  67.                             <input type="hidden" name="uri" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
  68.                             <input type="submit" name="do" value="<?php echo $lang['update_text'] ?>"/>
  69.                             <input type="submit" name="do" value="<?php echo $lang['delete_text'] ?>"/>
  70.                         </form>
  71.                         <?php
  72.                     }
  73.                     ?>
  74.                 </fieldset>
  75.             </div>