Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] problema al llamar una función javascript en php

Estas en el tema de problema al llamar una función javascript en php en el foro de PHP en Foros del Web. Buenas noches. Tengo el problema al llamar una función javascript. Yo hago un if preguntando si el botón salve fue seleccionado en php y guardo ...
  #1 (permalink)  
Antiguo 15/03/2013, 19:25
 
Fecha de Ingreso: abril-2011
Mensajes: 8
Antigüedad: 13 años
Puntos: 0
Pregunta problema al llamar una función javascript en php

Buenas noches.

Tengo el problema al llamar una función javascript.
Yo hago un if preguntando si el botón salve fue seleccionado en php y guardo los datos, y luego llamo la función datos() hecha en javascript.
pero no me llama la función datos. Me podrían ayudar. Gracias.
Les dejo el código que utilizo.

Código HTML:
<?PHP
require 'conexions.php';
	require 'funciones.php';
	$conexion=Conectarse(); //select numpro, numcot from PROYECTO where numpro = $_GET[numpro]
	$cargo=mysql_query("SELECT numcargo,nomcargo FROM cargo;",$conexion);
	if($save){
		$sql="insert into com_prov ( nit,nom_prov,id_estado) values('".$nom."','".$nom."','15')";
		//echo $sql;
		mysql_query($sql,$conexion);
		$sql="insert into com_conctato (nit_prov,cargo,nomcont,tel) values('".$nom."','".$cargos."','".$contacto."','".$tel."')";
		//echo $sql;
		mysql_query($sql,$conexion);
		echo "<script> datos();</script>";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<script>
	function datos(){
		var valor=document.form1.nom.value;
		opener.document.form_soli.idprove.value=valor;
		opener.document.form_soli.prov.add(new Option(valor, valor), null);
		window.close();
	}
</script>
<style type="text/css">
<!--
.Estilo1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>

<body onload="window.focus()">
<form id="form1" name="form1" method="post"  action="" enctype="multipart/form-data">
<table width="307" border="0" align="center" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td width="21" height="34" ><img name="plantilla_r1_c1" src="img/plantilla_r1_c1.gif" width="21" height="34" border="0" alt=""></td>
      <td width="1012" valign="top" background="img/plantilla_r1_c20.gif"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td width="24" ><img name="plantilla_r1_c3" src="img/plantilla_r1_c3.gif" width="24" height="34" border="0" alt=""></td>
   </tr>
<tr>
<td background="img/plantilla_r2_c1.gif">&nbsp;</td>
<td valign="top">
  <table width="552" border="0" align="center" bordercolor="#F0F0F0" bgcolor="#E0E5EE">
    <tr bgcolor="#666666">
      <td colspan="2" bgcolor="#5E7694"><div align="center" class="Estilo1">DATOS DEL PROVEEDOR </div></td>
    </tr>
   <?php /*?> <tr>
      <td width="224">IDENTIFICACION</td>
      <td width="277"><!--<input type="text" name="textfield2" />-->
      <input name="idprove" id="idprove" type="text" size="25" /></td>
    </tr><?php */?>
    <tr>
      <td>NOMBRE O RAZON SOCIAL </td>
      <td><!--<input type="text" name="textfield3" />-->
      <input name="nom" type="text" id="nom" value="<?php echo $nom;?>" size="45" /></td>
    </tr>
    <tr>
      <td>CONCTATO</td>
      <td><input name="contacto" id="contacto" type="text" size="45"/></td>
    </tr>
    <tr>
      <td>TELEFONO</td>
      <td><input name="tel" id="tel" type="text" size="25" /></td>
    </tr>
    <tr>
      <td>CARGO</td>
      <td><select name="cargos" id="cargos">
          <option value="">&lt;Seleccione uno&gt;</option>
          <?php
		  while ($fila=mysql_fetch_array($cargo)){
		  echo"<option value='".$fila["numcargo"] ."'>".$fila["nomcargo"]."</option>";
		  }
		  //
		  ?>
        </select></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
        <input type="submit" name="save" id="save" value="Enviar"/>
      </div></td>
    </tr>
  </table>
   <td background="img/plantilla_r2_c3.gif"></td>
</tr>
    <tr>
      <td height="23" ><img name="plantilla_r3_c1" src="img/plantilla_r3_c1.gif" width="21" height="23" border="0" alt=""></td>
      <td valign="top" background="img/plantilla_r3_c2.gif" ><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td ><img name="plantilla_r3_c3" src="img/plantilla_r3_c3.gif" width="24" height="23" border="0" alt=""></td>    
	</tr>
 </table>
</form>
  <p></p> 
</body>
</html> 
  #2 (permalink)  
Antiguo 15/03/2013, 19:33
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: problema al llamar una función javascript en php

Por flujo, con PHP imprimes la llamada de la función Javascript mucho antes de definirla en el documento.

Entiende que el orden de ejecución es de arriba hacia abajo, por lo cual debes ejecutar la función después de definirla, no al revés.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 15/03/2013, 20:35
 
Fecha de Ingreso: abril-2011
Mensajes: 8
Antigüedad: 13 años
Puntos: 0
Respuesta: problema al llamar una función javascript en php

Gracias, tienes razón pateketrueke.

Etiquetas: html, javascript, mysql, select, sql
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 06:13.