Foros del Web » Programando para Internet » Javascript »

AYUDA POR FAVOR! JavaScript y PHP

Estas en el tema de AYUDA POR FAVOR! JavaScript y PHP en el foro de Javascript en Foros del Web. Hola a tod@s, bueno necesito una ayudita con JavaScript y PHP, no hay manera de conseguir unirlos. Bien os comento, tengo un JavaScript que lo ...
  #1 (permalink)  
Antiguo 24/07/2008, 11:32
 
Fecha de Ingreso: febrero-2007
Mensajes: 80
Antigüedad: 17 años, 3 meses
Puntos: 0
Exclamación AYUDA POR FAVOR! JavaScript y PHP

Hola a tod@s, bueno necesito una ayudita con JavaScript y PHP, no hay manera de conseguir unirlos.
Bien os comento, tengo un JavaScript que lo que me hace es crear INPUTS cada vez que le doy a un botton, hasta ahi bien, el problema viene al querer que al crear un INPUT y que al lado del INPUT haya un codigo PHP y cada vez se repita ya que el funcionamiento es el siguiente, tenemos un INPUT type=text, entonces al lado tenemos un texto que poner BUSCAR PRODUCTO, se abre una nueva capa y salta una página, es decir, la de buscarproducto.php, vale buscamos seleccionamos el que queremos y nos inserta en el INPUT el CODIGO del producto y donde ponia BUSCAR PRODUCTO pondrá el nombre del producto, vale para hacerlo una vez bien, ahora es repetir la secuencia JavaScript y PHP cada vez que le doy al boton añadir un nuevo INPUT

El codigo JavaScript con el HTML es este:
Código PHP:
<script>

var 
i=1;

function 
fEscribeDir()
{
addFormField(document.formu1,'text','producto'+i);
document.formu1.numficheros.value=i;
i=i+1;
}
function 
addFormField (formfieldTypefieldNamefieldValue)
{
if (
document.getElementById)
{
var 
input document.createElement('INPUT');
var 
div document.createElement('DIV');
var 
input document.createElement('INPUT');

if (
document.all)

input.type fieldType;
input.name fieldName;
input.value fieldValue;
}
else if (
document.getElementById)

input.setAttribute('type'fieldType);
input.setAttribute('name'fieldName);



}

input.style.width="320px";
div.appendChild(input);
document.getElementById('ficheros').appendChild(div);
}
}
</script>




<table width="723" border="0.">
  <tr>
    <td width="329"><form name="FrmUpload">

<div id="ficheros">
  <input type="text" name="fichero0" style="width: 320px;">
<label></label>
</div>

</form> </td>
    <td width="186">&nbsp;</td>
    <td width="194"><input type="button" name="boton" id="boton" value="Añadir otro fichero" onClick="javascript:fEscribeDir()"></td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table> 

y este es el codigo php:

Código PHP:
<?
              $nproducto 
$_GET['nproducto'];
              if(!isset(
$nproducto)) {
              
?>

            <div id="buscarproducto" style=" background-color: #FFFFFF; width: 600px; height: 420px; position: absolute; float: left; left: 192px; top: 28px;display: none;">
<div align="right"><a href="#" onClick="document.getElementById('buscarproducto').style.display='none';return false;">CERRAR VENTANA</a></div>
                        <script>

    document.write('<iframe src="buscarproducto.php?idc='+document.getElementById('id').value+'&nombrec='+document.getElementById('nombreclient').value+'" width=600 height=400 border=0 scrolling=no></iframe>');
</script>    </div>
          <a href="#" onClick="document.getElementById('buscarproducto').style.display='';return false;">BUSCAR PRODUCTO </a>
            <?
              
} else {
              echo 
$nproducto;
              }
?>



JUNTO quedaría asi:

Código PHP:
<script>

var i=1;

function fEscribeDir()
{
addFormField(document.formu1,'text','producto'+i);
document.formu1.numficheros.value=i;
i=i+1;
}
function addFormField (form, fieldType, fieldName, fieldValue)
{
if (document.getElementById)
{
var input = document.createElement('INPUT');
var div = document.createElement('DIV');
var input = document.createElement('INPUT');

if (document.all)

input.type = fieldType;
input.name = fieldName;
input.value = fieldValue;
}
else if (document.getElementById)

input.setAttribute('type', fieldType);
input.setAttribute('name', fieldName);



}

input.style.width="320px";
div.appendChild(input);
document.getElementById('ficheros').appendChild(div);
}
}
</script>




<table width="723" border="0.">
  <tr>
    <td width="329"><form name="FrmUpload">

<div id="ficheros">
  <input type="text" name="fichero0" style="width: 320px;">
<label></label>
</div>

</form> </td>
    <td width="186"><?
              $nproducto 
$_GET['nproducto'];
              if(!isset(
$nproducto)) {
              
?>

            <div id="buscarproducto" style=" background-color: #FFFFFF; width: 600px; height: 420px; position: absolute; float: left; left: 192px; top: 28px;display: none;">
<div align="right"><a href="#" onClick="document.getElementById('buscarproducto').style.display='none';return false;">CERRAR VENTANA</a></div>
                        <script>

    document.write('<iframe src="buscarproducto.php?idc='+document.getElementById('id').value+'&nombrec='+document.getElementById('nombreclient').value+'" width=600 height=400 border=0 scrolling=no></iframe>');
</script>    </div>
          <a href="#" onClick="document.getElementById('buscarproducto').style.display='';return false;">BUSCAR PRODUCTO </a>
            <?
              
} else {
              echo 
$nproducto;
              }
?></td>
    <td width="194"><input type="button" name="boton" id="boton" value="Añadir otro fichero" onClick="javascript:fEscribeDir()"></td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>


De esta manera, el codigo funciona bien, pero a la hora de dar al boton Añadir otro fichero, se añade otro INPUT pero no se pone otra vez el codigo PHP y eso es realmente lo que necesito hacer


DEsde ya muchas gracias y espero una solucion
MIL GRACIAS!!
  #2 (permalink)  
Antiguo 28/07/2008, 05:04
 
Fecha de Ingreso: febrero-2007
Mensajes: 80
Antigüedad: 17 años, 3 meses
Puntos: 0
Respuesta: AYUDA POR FAVOR! JavaScript y PHP

¿Alguien? Siento el doble POST, pero esque se fuee a tomar x ai ya el post...

SORRY!!
  #3 (permalink)  
Antiguo 28/07/2008, 17:42
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: AYUDA POR FAVOR! JavaScript y PHP

Estás mezclando demasiado.
No se repetirá el código PHP por un motivo muy simple: php se ejecuta EN EL SERVIDOR y su salida es html. Jamás verás código PHP mezclado con HTML.

Tendrás que reestructurar tu página, que lo que tenga que hacer javascript lo haga javascript, y si necesitás peticiones tendrás que recargar la página, o abrir una nueva.


Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:32.