Ir para conteúdo
Fórum Script Brasil
  • 0

Como Dar Valor Ao Campo No Formulário


Maccoy

Pergunta

Tudo bem pessoal

Criei algumas funções em JavaScript simplesmente para fazer cálculos simples em um formulário, só que quando preencho tudo, a primeira linha do "pedido" funciona normalmente mas as outras que tem a mesma função (só muda o número) não exibem o valor em um dos campos, mas sei que a variável está com o valor pois todos os outros cálculos que dependem dela funcionam normalmente, só que precisava que o valor da mesma fosse exibido no campo do formulário, coisa que não está acontecendo.

Segue o código abaixo:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>..::HENAR::..</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>

<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

//-->

function soma1(x)  //é x porque é um parâmetro

{

valor=(x.qtde1.value)*(x.valor_desc1.value);

x.totalu1.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde1.value > 0)

{

  x.totalu1.value=x.qtde1.value*x.valor_desc1.value;

}

somaTotal();

}

function soma2(x)  //é x porque é um parâmetro

{

valor=(x.qtde2.value)*(x.valor_desc2.value);

x.totalu2.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde2.value > 0)

{

  x.totalu2.value=x.qtde2.value*x.valor_desc2.value;

}

somaTotal();

}

function soma3(x)  //é x porque é um parâmetro

{

valor=(x.qtde3.value)*(x.valor_desc3.value);

x.totalu3.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde3.value > 0)

{

  x.totalu3.value=x.qtde3.value*x.valor_desc3.value;

}

somaTotal();

}

function soma4(x)  //é x porque é um parâmetro

{

valor=(x.qtde4.value)*(x.valor_desc4.value);

x.totalu4.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde1.value > 0)

{

  x.totalu4.value=x.qtde4.value*x.valor_desc4.value;

}

somaTotal();

}

function soma5(x)  //é x porque é um parâmetro

{

valor=(x.qtde5.value)*(x.valor_desc5.value);

x.totalu5.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde5.value > 0)

{

  x.totalu5.value=x.qtde5.value*x.valor_desc5.value;

}

somaTotal();

}

function soma6(x)  //é x porque é um parâmetro

{

valor=(x.qtde6.value)*(x.valor_desc6.value);

x.totalu6.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde6.value > 0)

{

  x.totalu6.value=x.qtde6.value*x.valor_desc6.value;

}

somaTotal();

}

function soma7(x)  //é x porque é um parâmetro

{

valor=(x.qtde7.value)*(x.valor_desc7.value);

x.totalu7.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde7.value > 0)

{

  x.totalu7.value=x.qtde7.value*x.valor_desc7.value;

}

somaTotal();

}

function soma8(x)  //é x porque é um parâmetro

{

valor=(x.qtde8.value)*(x.valor_desc8.value);

x.totalu8.value=valor; //é para atribuir o 'valor' a caixa do resultado

if (x.qtde8.value > 0)

{

  x.totalu8.value=x.qtde8.value*x.valor_desc8.value;

}

somaTotal();

}

function desconto1(x)

{

aux=(x.valoru1.value*x.desc1.value)/100;

x.valor_desc1.value=x.valoru1.value-aux;

soma1(x);

}

function desconto2(x)

{

aux=(x.valoru2.value*x.desc2.value)/100;

x.valor_desc2.value=x.valoru2.value-aux;

soma2(x);

}

function desconto3(x)

{

aux=(x.valoru3.value*x.desc3.value)/100;

x.valor_desc3.value=x.valoru3.value-aux;

soma3(x);

}

function desconto4(x)

{

aux=(x.valoru4.value*x.desc4.value)/100;

x.valor_desc4.value=x.valoru4.value-aux;

soma4(x);

}

function desconto5(x)

{

aux=(x.valoru5.value*x.desc5.value)/100;

x.valor_desc5.value=x.valoru5.value-aux;

soma5(x);

}

function desconto6(x)

{

aux=(x.valoru6.value*x.desc6.value)/100;

x.valor_desc6.value=x.valoru6.value-aux;

soma6(x);

}

function desconto7(x)

{

aux=(x.valoru7.value*x.desc7.value)/100;

x.valor_desc7.value=x.valoru7.value-aux;

soma7(x);

}

function desconto8(x)

{

aux=(x.valoru8.value*x.desc8.value)/100;

x.valor_desc8.value=x.valoru8.value-aux;

soma8(x);

}

function validacao()

{

    pedido.qtde1.focus();

}                

function somaTotal()

{

   total=parseFloat(pedido.totalu1.value)+parseFloat(pedido.totalu2.value)+parseFloat(pedido.totalu3.value)+parseFloat(pedido.totalu4.value)+parseFloat(pedido.totalu5.value)+parseFloat(pedido.totalu6.value)+parseFloat(pedido.totalu7.value)+parseFloat(pedido.totalu8.value);

   pedido.total_geral.value=total;

}

function ValidaForm()

{

   aux=0;

   if (pedido.totalu1.value != 0 || 0.0)

   {

      if ((pedido.qtde1.value || pedido.modelo1.value || pedido.valoru1.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde1.focus();

         aux=1;

      }

   }

   if (pedido.totalu2.value != 0 || 0.0)

   {

      if ((pedido.qtde2.value || pedido.modelo2.value || pedido.valoru2.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde2.focus();

         aux=1;

      }

   }

   if (pedido.totalu3.value != 0 || 0.0)

   {

      if ((pedido.qtde3.value || pedido.modelo3.value || pedido.valoru3.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde3.focus();

         aux=1;

      }

   }

   if (pedido.totalu4.value != 0 || 0.0)

   {

      if ((pedido.qtde4.value || pedido.modelo4.value || pedido.valoru4.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde4.focus();

         aux=1;

      }

   }

   if (pedido.totalu5.value != 0 || 0.0)

   {

      if ((pedido.qtde5.value || pedido.modelo5.value || pedido.valoru5.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde5.focus();

         aux=1;

      }

   }

   if (pedido.totalu6.value != 0 || 0.0)

   {

      if ((pedido.qtde6.value || pedido.modelo6.value || pedido.valoru6.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde6.focus();

         aux=1;

      }

   }

   if (pedido.totalu7.value != 0 || 0.0)

   {

      if ((pedido.qtde7.value || pedido.modelo7.value || pedido.valoru7.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde7.focus();

         aux=1;

      }

   }

   if (pedido.totalu8.value != 0 || 0.0)

   {

      if ((pedido.qtde8.value || pedido.modelo8.value || pedido.valoru8.value) == "")

      {

         alert ("Existem Campos não preenchidos no Pedido!");

         pedido.qtde8.focus();

         aux=1;

      }

   }

   if ((pedido.totalu1.value == 0 || 0.0)&&(pedido.totalu2.value == 0 || 0.0)&&(pedido.totalu3.value == 0 || 0.0)&&(pedido.totalu4.value == 0 || 0.0)&&(pedido.totalu5.value == 0 || 0.0)&&(pedido.totalu6.value == 0 || 0.0)&&(pedido.totalu7.value == 0 || 0.0)&&(pedido.totalu8.value == 0 || 0.0))

   {

      alert ("Você precisa inserir pelo menos um Produto no Pedido!");

      pedido.qtde1.focus();

      aux=1;

   }

   if (aux != 1)

   {

     pedido.submit();

   }

      

}  

</script>

</head>

<body background="fundo.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FFFFFF" alink="#FFFFFF" vlink="#FFFFFF">

<table width="100%" height="85%" border="0" cellpadding="0" cellspacing="0">

  <tr>

    <td>

<table width="770" border="0" align="center" cellpadding="0" cellspacing="0">

        <tr>

          <td width="770"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="770" height="150">

              <param name="movie" value="top.swf">

              <param name="quality" value="high">

              <embed src="top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="770" height="150"></embed></object></td>

        </tr>

        <tr>

          <td><p><img src="empty.gif" width="2" height="2"></p></td>

        </tr>

          <?

          include ("menu.php");

          ?>

        <tr>

          <td bgcolor="#FFFFFF">&nbsp;</td>

        </tr>

        <tr>

          <td><table width="768" border="1" cellpadding="0" cellspacing="0" bordercolor="#993333">

              <tr>

                <td width="764"><table width="764" border="0" cellpadding="0" cellspacing="4" bgcolor="#FFFFFF">

                    <tr>

                      <td width="756"><table width="750" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">

                          <tr>

                            <td>

                              <div align="center">

                                <table width="749" border="0" cellspacing="5" cellpadding="0">

                                  <tr>

                                    <td width="412" bgcolor="eefafd"> <form action="" method="post" name="pedido" target="_parent">

                                        <table width="713" border="0" align="center" cellpadding="0" cellspacing="0">

                                          <tr>

                                            <td colspan="4"><strong><font color="#993333" size="2" face="Verdana, Arial, Helvetica, sans-serif">Pedido</font></strong></td>

                                          </tr>

                                          <tr>

                                            <td width="112">&nbsp;</td>

                                            <td width="283">&nbsp;</td>

                                            <td width="65">&nbsp;</td>

                                            <td width="253">&nbsp;</td>

                                          </tr>

                                          <tr>

                                            <td colspan="4"> <div align="center">

                                                <table width="705" border="0" cellspacing="0" cellpadding="0">

                                                  <tr>

                                                    <td width="256"><img src="logo_metavila.gif" width="256" height="103"></td>

                                                    <td width="436" valign="top">

                                                      <div align="center"><font color="#0033CC" size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>MET&Aacute;VILA

                                                        IND&Uacute;STRIA METAL&Uacute;RGICA

                                                        LTDA.</strong></font></div></td>

                                                  </tr>

                                                </table>

                                              </div></td>

                                          </tr>

                                          <tr>

                                            <td>&nbsp;</td>

                                            <td colspan="3" valign="top">&nbsp;</td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Cliente:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="cliente" type="text" id="nome2" size="40" maxlength="50">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">E-mail:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="email" type="text" id="email2" size="40" maxlength="40">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Endere&ccedil;o:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="endereco" type="text" id="endereco" size="40" maxlength="60">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Bairro:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="bairro" type="text" id="bairro" size="40" maxlength="50">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Cidade:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="cidade" type="text" id="cidade" size="40" maxlength="40">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Estado:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="estado" type="text" id="estado" size="40" maxlength="30">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">CEP:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="cep" type="text" id="cep" size="40" maxlength="9">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">CNPJ:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="cnpj" type="text" id="cnpj2" size="40" maxlength="40">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Incr.

                                              Est.:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="ie" type="text" id="ie" size="40" maxlength="30">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Telefone:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="telefone" type="text" id="telefone2" size="40" maxlength="10">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Comprador:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="comprador" type="text" id="comprador" size="40" maxlength="40">

                                              </font></td>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Assunto:</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input name="assunto" type="text" id="assunto2" value="Pedido" size="40" maxlength="40">

                                              </font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                          </tr>

                                          <tr>

                                            <td><font color="#0033CC" size="2" face="Verdana, Arial, Helvetica, sans-serif">Frete:</font></td>

                                            <td> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input type="radio" name="frete" value="CIF">

                                              <font color="#0033CC">CIF</font></font>

                                              <font size="2" face="Verdana, Arial, Helvetica, sans-serif">

                                              <input type="radio" name="frete" value="FOB">

                                              <font color="#0033CC">FOB<font color="#FFFFFF">-.</font></font></font>

                                            </td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                                            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>

                               &nbs

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...