I have a form with the vendor and product fields, I want that after these two items are completed the price of the product field is automatically filled in accordance with the vendor and product inserted (remembering that there is a price table where you register the product price and vendor product).

Can anyone help me ... thanks

Recommended Answers

All 3 Replies

With price table - you mean in database or html table? If in database, we will need AJAX.

You want a review page of the information before submission?

My code...
form.php

<!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=utf-8" />
<script type="text/javascript">
function abre_conv(){
        window.open('form_busca_conv.php', 'fornruq1w2w', 'top=110, left=110, width=480, height=395');
}
function abre_exa(){
        window.open('form_busca_exa.php', 'fornruq1w2w', 'top=110, left=110, width=480, height=395');
}
function getHTTPObject()
{
        if(window.XMLHttpRequest){
                return new XMLHttpRequest();
        } else if(window.ActiveXObject){
                var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
                
                for(var i = 0; i < prefixes.length; i++){
                        try{
                            return new ActiveXObject(prefixes[i] + ".XMLHTTP");
                        } catch (e) {}
                }
        }
}
var xmlHttp = getHTTPObject();
function busca_valor(conv, exa)
{        
        id('tf_agendamento_paciente_valor_exame').innerHTML = 'Carregando...';
        xmlHttp.open("GET", "busca_preco.php?conv="+conv+"&exa="+exa, true);

        xmlHttp.onreadystatechange = function()
        {
                if (xmlHttp.readyState==4)
                {
                        id('tf_agendamento_paciente_valor_exame').innerHTML = xmlHttp.responseText;
                }
        }
        xmlHttp.send(null);   
}
function id(el){
        return document.getElementById(el);
}
window.onload = function()
{
        id('hf_agendamento_paciente_convenio').onblur = function()
        {
               var conv = document.getElementById("hf_agendamento_paciente_convenio").value;
        }
                id('hf_agendamento_paciente_exame').onblur = function()
        {
                var exa = document.getElementById("hf_agendamento_paciente_exame").value;               
        }
                busca_valor(conv,exa);
}
</script>
<title>Untitled Document</title>
</head>

<body>
<table width="776" border="0" cellspacing="4" cellpadding="0">
<tr>
    <td> </td>
    <td colspan="2">Convênio:<input type="hidden" name="hf_agendamento_paciente_convenio" id="hf_agendamento_paciente_convenio"/></td>    
    <td>Matrícula:</td>
    <td>Nro Guia:</td>
  </tr>
  <tr>
    <td> </td>
    <td colspan="2"><input name="tf_agendamento_paciente_convenio" type="text" id="tf_agendamento_paciente_convenio" size="60"/><input type="button" name="button2" id="button2" value="..." onclick="abre_conv()"/></td>
    <td><input name="tf_agendamento_paciente_matricula" type="text" id="tf_agendamento_paciente_matricula" size="20" /></td>
    <td><input name="tf_agendamento_paciente_num_guia" type="text" id="tf_agendamento_paciente_num_guia" size="20" /></td>
  </tr>
<tr>
    <td>&nbsp;</td>
    <td colspan="2">Exame:<input type="hidden" name="hf_agendamento_paciente_exame" id="hf_agendamento_paciente_exame"/></td>
    <td>Valor Exame:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2"><input name="tf_agendamento_paciente_exame" type="text" id="tf_agendamento_paciente_exame" size="60"/><input type="button" name="button2" id="button2" value="..." onclick="abre_exa()"/></td>
    <td><input name="tf_agendamento_paciente_valor_exame" type="text" id="tf_agendamento_paciente_valor_exame" size="20" /></td>
    <td>&nbsp;</td>
  </tr>
  </table>
</body>
</html>

form_busca_convenio.php

<!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=utf-8" />
<title>..::Radiologyx&gt;&gt;Agendamento&gt;&gt;Cadastro&gt;&gt;Convênios:
:..</title>
<link href="../css/ris.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="../js/convenio.js"></script>
<style type="text/css">
td div { 
height:150px; 
width:467px;
overflow:auto; 
}
</style>
</head>
<body>
<table width="450" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top"><img src="../images/interface/lista_conv.gif" width="467" height="20" /></td>
  </tr>
  <tr>
    <td valign="top"><form id="form1" name="form1" method="post" action="form_busca_conv.php">
      <table width="450" border="0" id="todoform" cellspacing="0" cellpadding="0">
        <tr>
          <td width="9" valign="top"> </td>
          <td width="432" valign="top"> </td>
          <td width="9" valign="top"> </td>
        </tr>
        <tr>
          <td colspan="2" valign="top">Nome:</td>
          <td width="9" valign="top"> </td>
        </tr>
        <tr>
          <td colspan="3" valign="top"><input name="tf_nome" type="text" id="tf_nome" size="40" maxlength="50" /></td>
        </tr>
        <tr>
          <td valign="top"> </td>
          <td valign="top"> </td>
          <td valign="top"> </td>
        </tr>
        <tr>
          <td colspan="3" valign="top">
          <table width="435" border="0" align="left" cellpadding="0" cellspacing="2">
            <tr>
              <td width="141" valign="top"><input type=image src="../images/interface/botao_busca.gif" width="130" height="50"></td>
              <td width="288" valign="top"><img src="../images/interface/botao_cancela.gif" width="130" height="50" border="0" onclick="window.close();"/></td>
            </tr>
          </table>
          </td>
          </tr>
        <tr>
          <td colspan="3" valign="top"> </td>
          </tr>
        <tr>
          <td colspan="3" valign="top">
          <?
                     echo "<table width=\"450\" border=0 cellpadding=\"0\" class=\"titulo_negrito\" cellspacing=\"4\">
                         <tr>
                         <td width=\"350\" align=\"left\">Nome:</td>    
                         <td width=\"100\" align=\"left\"></td>                                                                 
                         </td>
                         </tr>
                         </table>";                       
                  ?>          
          <div>
            <?
                             include "../banco/conecta.php";                             
                                 
                                 if(isset($_POST['tf_nome']))
                                 {
                                   $nome = trim(strtoupper($_POST['tf_nome']));
                                   $sql = "SELECT convenio_nome, convenio_id FROM glo_convenios where convenio_nome like '$nome%' and convenio_status='1' order by convenio_nome ASC";
                                   $result = pg_query($conexao,$sql);
                                   $i = 1;                                      
                                         
                                   while ($show = pg_fetch_object($result))
                                   {
                                         $nome = $show->convenio_nome;                                  
                                         $id = $show->convenio_id;                                       
                                         $i++;
                                        
                                         if(($i%2)!=0){                                                                                                                                    
                                         echo "<table width=\"450\" border=0 cellpadding=\"0\" class=\"texto\" cellspacing=\"4\">
                                         <tr>   
                                         <td width=\"350\" align=\"left\"><input type=\"radio\" name=\"rg_con\" value=\"$nome|$id\">$nome</td>           
                                     <td width=\"100\" align=\"left\"></td>
                                         </tr>
                                         </table>";}
                                         
                                         else{
                                         echo "<table width=\"450\" bgcolor=\"#D6D6D6\" border=0 cellpadding=\"0\" class=\"texto\" cellspacing=\"4\">
                                         <tr>
                                         <td width=\"350\" align=\"left\"><input type=\"radio\" name=\"rg_con\" value=\"$nome|$id\">$nome</td>           
                                     <td width=\"100\" align=\"left\"></td>
                                         </tr>
                                         </table>";}                                       
                                   }                             
                                   pg_close($conexao);                                   
                                 }
                                 
                                 else
                                 {                              
                                   $sql = "SELECT convenio_nome, convenio_id FROM glo_convenios where convenio_status='1' order by convenio_nome ASC";
                                   $result = pg_query($conexao,$sql);
                                   $i = 1;
                                         
                                   while ($show = pg_fetch_object($result))
                                   {
                                         $nome = $show->convenio_nome;                                  
                                         $id = $show->convenio_id;                                       
                                         $i++;
                                        
                                         if(($i%2)!=0){                                                                                                                                    
                                         echo "<table width=\"450\" border=0 cellpadding=\"0\" class=\"texto\" cellspacing=\"4\">
                                         <tr>                                   
                                         <td width=\"350\" align=\"left\"><input type=\"radio\" name=\"rg_con\" value=\"$nome|$id\">$nome</td>           
                                     <td width=\"100\" align=\"left\"></td>
                                         </tr>
                                         </table>";}
                                         
                                         else{
                                         echo "<table width=\"450\" bgcolor=\"#D6D6D6\" border=0 cellpadding=\"0\" class=\"texto\" cellspacing=\"4\">
                                         <tr>
                                        <td width=\"350\" align=\"left\"><input type=\"radio\" name=\"rg_con\" value=\"$nome|$id\">$nome</td>            
                                     <td width=\"100\" align=\"left\"></td>
                                         </tr>
                                         </table>";}                                       
                                   }                             
                                   pg_close($conexao);
                                }
               ?>    
          </div></td>
          </tr>
        <tr>
          <td valign="top"> </td>
          <td valign="top"> </td>
          <td valign="top"> </td>
        </tr>
        <tr>
          <td valign="top"> </td>
          <td valign="top"><table width="432" border="0" cellspacing="0" cellpadding="0">
            <tr>
         <td align="center"><img src="../images/interface/botao_seleciona.gif" onclick="selecionar()" width="130" height="50" /></td>
         <td align="center"><img src="../images/interface/botao_inclui.gif" onclick="adicionar()" width="130" height="50" /></td>
         <td align="center"><img src="../images/interface/botao_edita.gif" onclick="editar()" width="130" height="50" /></td>
            </tr>
          </table></td>
          <td valign="top"> </td>
          </tr>
      </table>
    </form></td>
  </tr>
</table>
</body>
</html>

convenio.js

function selecionar(){
  var perfil;
  perfil = document.form1.rg_con.value;
  for(var i=0;i<document.form1.rg_con.length;i++){
          if(document.form1.rg_con[i].checked){
                 perfil = document.form1.rg_con[i].value;
                 break;
          }             
  }
  if(perfil){
          var partes = perfil.split('|');
          window.opener.document.getElementById("tf_agendamento_paciente_convenio").value = partes[0];
          window.opener.document.getElementById("hf_agendamento_paciente_convenio").value = partes[1]; 
          window.close();
  }else{
          alert("Selecione um convenio.");
  }
}
function editar(){
  var perfil;
  perfil = document.form1.rg_con.value;
  for(var i=0;i<document.form1.rg_con.length;i++){
          if(document.form1.rg_con[i].checked){
                 perfil = document.form1.rg_con[i].value;
                 break;
          }             
  }
  if(perfil){
          var partes = perfil.split('|');
          window.open('form_edita_conv.php?id=' + partes[1], 'Teste44', 'top=110, left=110, width=473, height=335');
          window.close();
  }else{
          alert("Selecione um convenio.");
  }
}
function adicionar(){
        window.open('form_add_conv.php', 'scisdade1', 'top=110, left=110, width=473, height=335'); 
         window.close();
}

busca_preco.php

<?php
header("Expires: {$gmtdate} GMT");
header("Last-Modified: {$gmtDate} GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Progma: no-cache");
include "banco/conecta.php";
$conv = $_GET['conv'];
$exa = $_GET['exa'];
$query = "select exame_preco_valor from rad_exames_precos where exame_preco_exame='$exa' and  exame_preco_convenio='$conv'";
$result = pg_query($conexao,$query);
$row = pg_fetch_object($result);
$valor = $row->exame_preco_valor;
echo $valor;
}
?>

Thanks guys!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.