hola a todos ....
tengo una gran pregunta.... acabo de hacer una lista desplegable con ajax ... cuando la persona elije un tipo de auto se despliega automaticamente el tipo de carroceria....
mi pregunta es como puedo guardar el valor del tipo de carroceria....
mi tabla datos_auto
tb tipo de vehiculos
Código MySQL:
Ver original
--
-- Volcar la base de datos para la tabla `tipo_vehi`
--
y mi codigo
Código HTML:
Ver original<!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"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="javascript" type="text/javascript" src="js/js.js">
function valida(){
var maximo ="2012"
// verifica si el campo marca esta vacia
if (document.formulario.marca.value==""){
alert("Debe Escribir La Marca Del Vehiculo.");
return false;
}
// verifica si el campo modelo esta vacio
if (document.formulario.modelo.value==""){
alert("Debe Escribir El Modelo Del Vehiculo.");
return false;
}
// verifica si el campo añp esta vacio
if (document.formulario.ano.value==""){
alert("Debe Escribir El Año Del Vehiculo.");
return false;
}
// verifica si el campo año es numerico
if (!IsNumeric(document.formulario.ano.value)){
alert("El Año del Vehiculo Debe Contener Solamente Numeros.");
return false;
}
// verifica si el campo año esta entre los años 1900 y el valor del maximo(2012)
if ((document.formulario.ano.value<1900)||(document.formulario.ano.value>maximo)){
alert("EL Año Del Vehiculo Debe Ser Entre 1990 y "+maximo".");
return false;
}
// verifica si el campo patente esta vacio
if ((document.formulario.patente.value==""){
alert("Debe Ingresar La Patente De Su Vehiculo.");
return false;
}
// verifica si el campo precio es numerico
if (!IsNumeric(document.formulario.precio.value)){
alert("Debe contener Solamente Numeros.");
return false;
}
// verifica si el campo precio esta vacio
if (document.formulario.precio.value==""){
alert("Debe Ingresar El Precio Del Vehiculo.");
return false;
}else{
document.formulario.precio.value=retInt(document.formulario.precio.value)
}
// Verificamos si la patente y el tipo de vehiculo es correcto
function RvalPat(sValor){
var ret = "";
if ((document.formulario.tipo.value=="A")||(document.formulario.tipo.value=="M"){
if ((document.formulario.patente.value.length<6)){
alert("La Patente Le Faltan Valores. Debe Contener 6 Caracteres.");
ret=""
}else{
ret = valPat(sValor);
}
}else{
ret = sValor;
}
return ret;
}
// verificacion para saber si la patente contiene numeros y letras
function valPat(fieldValue){
// LLNNNN o LLLLNN (donde X=letra, N=Numero). :/ me pregunto donde esta la X
var ClearfieldValue ="";
var iChars="1234567890";
var aChars = /[(A-Z)|(a-z)]/ ;
if (aChars.test(fieldValue.charAt(3)) ){
// SIGNIFICA que el 4 caracter es una letra entre a y Z
// Ahora veremos si los 4 primeros cumplen la misma funcion
if ((aChars.test(fieldValue.charAt(0))) && (aChars.test(fieldValue.charAt(1))) && (aChars.test(fieldValue.charAt(2))) && (aChars.test(fieldValue.charAt(3)))){
// AHORA COMPROBAMOS LOS 2 ultimos caracteres para que sean numericos.
if ((!(iChars.indexOf(fieldValue.charAt(4)) == -1)) && (!(iChars.indexOf(fieldValue.charAt(5)) == -1))){
// TODO OK entonces RETORNAMOS con MAYUSCULAS
ClearfieldValue = fieldValue.toUpperCase()
}
}
}else{
if (aChars.test(fieldValue.charAt(1)) ){
// SIGNIFICA que el 2 caracter es una letra entre a y Z
// Ahora veremos si los 2 primeros cumplen la misma funcion
if ((aChars.test(fieldValue.charAt(0))) && (aChars.test(fieldValue.charAt(1)))){
// AHORA COMPROBAMOS LOS 4 ultimos caracteres para que sean numericos.
if ((!(iChars.indexOf(fieldValue.charAt(2)) == -1)) && (!(iChars.indexOf(fieldValue.charAt(3)) == -1)) && (!(iChars.indexOf(fieldValue.charAt(4)) == -1)) && (!(iChars.indexOf(fieldValue.charAt(5)) == -1))){
// TODO OK entonces RETORNAMOS con MAYUSCULAS
ClearfieldValue = fieldValue.toUpperCase()
}
}
}
}
return ClearfieldValue;
}
function retInt(fieldValue) {
var i=0;
var ClearfieldValue ="";
var iChars="1234567890";
for (i=0; i < fieldValue.length;i++) {
if (!(iChars.indexOf(fieldValue.charAt(i)) == -1)) {
ClearfieldValue = ClearfieldValue+""+ fieldValue.charAt(i);
}
}
return ClearfieldValue;
}
}
<!--
.Estilo1 {
color: #FF0000;
font-size:14px;
font-family:Arial, Helvetica, sans-serif;
}
.Estilo5 {color: #666666}
-->
<h1 align="center">Registrar Vehiculo
</h1> <table align="center" border="1" width="90%" bgcolor="#CCCCCC"> <form method="post" name="formulario" action="insertar.php"> <td width="171"> <select name="nuevo">Seleccione Una Opcion...
<td width="171"> <?php include ('tipo_vehiculo.php');?></td>
<td width="171"> <input type="text" name="marca" /></td> <td width="171"> <input type="text" name="modelo" /></td>
<td width="171"> <input type="text" name="ano" size="8" /></td> <td width="171"> <input type="text" name="patente" size="8" maxlength="6" onBlur="this.value = RvalPat(this.value)"/></td>
<td width="171"> <input type="text" name="pesos" maxlength="11" onBlur="this.value=retInt(this.value)"/></td> <td width="171" align="center"><input type="checkbox" name="radio" /></td> <td width="171"> <input type="file" name="imagen " /></td> <td width="171" align="center"><input type="checkbox" name="alarma"/></td> <td><input type="submit" value="Enviar" onclick="valida()"></td>
aca es donde lo guardo...
Código PHP:
Ver original<?php
include('conexion.php');
$nuevo = $_POST['nuevo'];
$tipovehi = $_POST['tipo'];
$carroceria = $_POST['carroceria'];
$marca = $_POST['marca'];
$modelo = $_POST['modelo'];
$ano = $_POST['ano'];
$patente = $_POST['patente'];
$precio = $_POST['precio'];
$otro = $_POST['otro'];
$radio = $_POST['radio'];
$alarma = $_POST['alarma'];
$ruta = $_FILES['imagen']['name'];
$inserta = "INSERT INTO datos_auto (nuevo, carroceria, modelo, ano, patente, tipo_vehi, marca, precio, otro, img1, radio, alarma) VALUES ('$nuevo','$carroceria','$modelo','$ano','$patente','$tipovehi','$marca','$precio','$otro','$ruta','$radio','$alarma')";
$consulta = "SELECT * FROM datos_auto WHERE patente = '$patente'";
if($numRegistro == 1)
{
echo"<script type='text/javascript'>
alert('EL Codigo Esta En La Base De Datos');
window.location='registro_vehiculo.php';
</script>";
}
else
{
echo"<script type='text/javascript'>
alert('Datos Del Automovil Ingresado correctamente');
window.location='registro_vehiculo.php';
</script>";
}
?>
Le ago un print_r($_POST) para saber que me esta tirando pero no me muestra el valor del select de la carroceria
gracias