Foros del Web » Programando para Internet » Javascript »

problemas con radio button

Estas en el tema de problemas con radio button en el foro de Javascript en Foros del Web. Hola que tal? Tengo el siguiente problema: Tengo un combobox con unas tallas y tengo unos radio buttons con colores, necesito que segun la combinacion ...
  #1 (permalink)  
Antiguo 14/12/2008, 19:25
 
Fecha de Ingreso: diciembre-2008
Mensajes: 1
Antigüedad: 15 años, 4 meses
Puntos: 0
problemas con radio button

Hola que tal?

Tengo el siguiente problema:
Tengo un combobox con unas tallas y tengo unos radio buttons con colores,
necesito que segun la combinacion de talla con color me de el precio de la prenda.
Por ejemplo: una playera talla S en color blanco me cuesta $20
y una playera talla S en color rojo me cuesta $23

El detalle esta en que al parecer no me toma los radiobuttons, me sale undefined si pongo un alert con la longitud de los radios, pero si puedo tomar el valor del combobox y puedo ponerle valor a un campo de texto. Aqui les dejo mi script.

El problema esta en la funcion incluir casi al final del codigo.

Código:
<? 	
include("config.php");
include("funciones.php");
$cnx=conectar();
$marca=$_GET["marca"];
$idert=$_GET["id"];
 	$server="localhost";
	$user="user";
	$pass="pass";
	$coneccion=mysql_connect($server,$user,$pass); 
	mysql_select_db("bkrcom_dimeo",$coneccion);
	$sql_hija="SELECT talla,color,precio FROM relacion WHERE codigo='$idert' ORDER BY id ASC"; 
?>
<!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>Untitled Document</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link href="estilos.css" rel="stylesheet" type="text/css" />

</head>
<body>
<?
	$sqlu="SELECT * FROM productos WHERE codigo='$idert' AND marca='$marca'";
	$resu=mysql_query($sqlu) or die (mysql_error());
	if (mysql_num_rows($resu)>0)
	  {
		while (list($id,$codigo,$nombre,$descripcion,$material,$peso,$marca,$fotografia) = mysql_fetch_array($resu))
			{
				$ide = $id;
				$code = $codigo;
				$nombree = $nombre;
				$descripcione = $descripcion;
				$materiale= $material;
				$pesoe = $peso;
				$marcae = $marca;
				$fotografiae=$fotografia;
			}
		}
	mysql_free_result($resu);
?>
    <form id="formulario" name="formulario" method="post" action="pedido.php" >
    <table width="898" border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td width="235" height="464" valign="top"><div align="center">   
<br />
    </div></td>
    <td width="648" valign="top"  class="texto">
    
    <table width="645" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td colspan="2"><img src="img/tit_<? echo "$marca"; ?>.gif" /></td>
        </tr>
        <tr>
          <td colspan="2"><br /></td>
        </tr>
        <tr>
          <td width="366" valign="top"><table width="361" height="180" border="0" cellspacing="0" cellpadding="3">
            <tr>
              <td width="361" height="93" valign="top"><div align="center"><span class="Modelo2"><img src="productos/<? echo "$fotografiae"; ?>.jpg"/></span></div></td>
            </tr>
            <tr>
              <td height="10"><img src="img/linea2.gif" width="360" height="3" /></td>
            </tr>
            <tr>
              <td height="11" valign="top" background="img/back_<? echo "$marca"; ?>.gif" class="textoBmod"><? echo "$code"; ?></td>
            </tr>
            <tr>
              <td height="5" valign="top" class="texto"><div align="left" class="texto12"><? echo "$nombree"; ?></div></td>
            </tr>
            <tr>
              <td height="6" valign="top" class="texto"><span class="texto2">Material: </span> <span class="textoN"><? echo "$materiale"; ?></span></td>
            </tr>
            <tr>
              <td height="11" valign="top" class="texto" ><span class="texto2">Tallas: </span> <span class="textoN">
              <select name="tallasw" id="tallasw" size="1" onChange='incluir(this.form.tallasw[selectedIndex].value);'>
                <?
					
					$sqlw="SELECT talla FROM relacion WHERE codigo='$idert' ORDER BY talla ASC";
					$resw=mysql_query($sqlw) or die (mysql_error());
					$talla_ant="";
					if (mysql_num_rows($resw)>0)
					  {
						$tallasarray = array();
						while (list($talla) = mysql_fetch_array($resw))
							{
								$nombre_sin=stripslashes($talla);
								if ($talla_ant!=$nombre_sin)
								  {
						?>
							<option value="<? echo $nombre_sin; ?>"><? echo utf8_encode($nombre_sin); ?></option>
                                    <?
									}
								$talla_ant=$nombre_sin;	
							}
					  }
					?>
              </select>
              </span></td>
            </tr>
            <tr>
              <td height="11" valign="top" class="texto">Peso: <span class="textoN"><? echo "$peso"; ?></span></td>
            </tr>
            <tr>
              <td height="11" valign="top" class="textoN">Descripci&oacute;n</td>
            </tr>
            <tr>
              <td height="11" valign="top" class="texto"><? echo "$des"; ?></td>
            </tr>
          </table></td>
          <td width="279" valign="top">
            <table width="276" border="0" cellspacing="2" cellpadding="0">
              <tr>
                <td class="textoN12">Colores</td>
              </tr>
              <?
					$sqlr="SELECT color FROM relacion WHERE codigo='$idert' ORDER BY color ASC";
					$resr=mysql_query($sqlr) or die (mysql_error());
					$conta=0;
					$color_ant="";
					if (mysql_num_rows($resr)>0)
					  {
						while (list($color) = mysql_fetch_array($resr))
							{
									$conta++;
									if($conta==1)
									{
										if ($color_ant!=$color)
											{
				?>
              <tr>	
                <td align="left" class="titulos">
                    <input type='radio' name='colorin' id='colorin' value='<? echo "$color"; ?>' checked='checked'/>
                  <? echo "$color"; ?></td>
                </tr>
              <? 							}
			 						}
									else
									{
										if ($color_ant!=$color)
											{
									?>
              <tr>	
                <td align="left" class="titulos"><label>
                    <input type='radio' name='colorin' id='colorin' value='<? echo "$color"; ?>' />
                  <? echo "$color"; ?></label></td>
                </tr>
              <? 	
			  								}
									}
			  						$color_ant=$color;
			  				}
						} ?>
              <tr>
                <td align="left" class="titulos">&nbsp;</td>
              </tr>
              <tr>
                <td align="left" class="titulos">Precio por pieza:<input id="precioso" name="precioso" type="text" class="campos2"  /></td>
              </tr>
              <tr>
                <td align="left" class="titulos">

<input name="ide" type="hidden" value="<? echo "$ide"; ?>" />
<input name="marca" type="hidden" value="<? echo "$marcae"; ?>" />
<input name="agregar_ped" type="hidden" id="agregar_ped" value="agregar" /></td>
              </tr>
              <tr>
                <td align="left" class="titulos">Cantidad
                  <label>
                    <input name="cantidad" type="text" class="campos2" id="cantidad" />
                  </label></td>
              </tr>
              <tr>
                <td align="left" class="titulos"><div align="left"><br />
                  <div align="left">
                          <input name="image2" type="image" value="cambiar" src="img-admin/agregarp.gif" img="img" accion="submit" />
                        </div>
                </div></td>
              </tr>
            </table>
                    
          </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
      </table>
      <br />
      <br />
  </p></td></tr>
</table></form>
<script lang="jscript"> 
function valores(campo1){ 
    this.campo1=campo1; 
}
<? 
$query_s=mysql_query($sql_hija,$coneccion); 
$indice=0; 
$cat=0; 
echo "var tallasarray= new Array();\n";
echo "var coloresarray= new Array();\n";
echo "var preciosarray= new Array();\n";
while($row=mysql_fetch_array($query_s)){ 
    echo "tallasarray[".$indice."]=new valores('".$row["talla"]."');\n";
	echo "coloresarray[".$indice."]=new valores('".$row["color"]."');\n";
	echo "preciosarray[".$indice."]=new valores('".$row["precio"]."');\n";
	$indice++;
}
?>
var j;

function incluir(vari){ 
	var i;
	var valor;
	alert(document.formulario.colorin.length);
    for (i=0;i<document.formulario.colorin.length;i++)
	{ 
	   if (document.formulario.colorin[i].checked)
	   	{
			 valor = document.formulario["colorin"][i].value;
			 //alert(valor); 
          	break; 
		}
    } 
	document.formulario.precioso.value="mundo";
	/*for(i=0; i<tallasarray.length; i++){ 
        	if ((tallasarray[i]==vari)&&(coloresarray[i]==option))
			{
				document.formulario.precioso.value=preciosarray[i];
			}
    } */
} 
</script>
</body>
</html>
les agradezco la ayuda.
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 10:27.