Hello everybody!

I need to get the values of two hidden fields and values that make a query in my database and return this column to a text field in the same form, I have already informed the forum here that can do that with Ajax, researched and made an example But it is not working. I am sending the code below, if someone can help me would be much appreciated


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" />
<title>..::Radiologyx&gt;&gt;Agendamento&gt;&gt;Cadastro&gt;&gt;Convênios:
:..</title>
<link href="../css/ris.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function eStatus(Status){
if(Status == 0){
  document.getElementById("tf_agendamento_paciente_matricula").style.display ='none';
  document.getElementById("tf_agendamento_paciente_num_guia").style.display ='none';
}else{
  document.getElementById("tf_agendamento_paciente_matricula").style.display ='block';
  document.getElementById("tf_agendamento_paciente_num_guia").style.display ='block';
}
}
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 seek_value(conv, exa)
{        
        id('tf_agendamento_paciente_valor_exame').innerHTML = 'Loading...';
        xmlHttp.open("GET", "seek_value.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>
</head>
<body>
<div id="edit_area_agenda">
<form id="todoform" name="todoform" method="post" action="banco/agenda_paciente.php" onSubmit="return validaAgenda()">
<table width="776" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td width="43">&nbsp;</td>
    <td width="399">Convênio:<input type="hidden" name="hf_agendamento_paciente_convenio" id="hf_agendamento_paciente_convenio"/></td>    
    <td width="147">Matrícula:</td>
    <td width="163">Nro Guia:</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><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>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><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>
</form>
</div>
</body>
</html>

seek_value.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;
}
?>

Help me please:S

Recommended Answers

All 2 Replies

At a glance, I would suggest use jquery for ajax calls - it is not to hard to familiarize with, and you will solve a few cross browser and waitfor problems.

Oh I have done something like this. What I ended up doing was I made a separate AJAX javascript. Then at the bottom of the AJAX JS I added a function set. What this does is it pulls the "values" of input/textarea fields even if they're hidden and adds them to a query string, and then passes it to the page that needs the information. eg: posttodb.php. Once the query string is setup in the page that will be calling on information from that you need to use if isset to get the variable values and map them. If this has completely confused you, I will post code for you.

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.