Does this code look wise?

Hi all
Quick question please, this code is inline in my webpage, it doesn’t look like it is the most efficient way. It appears to be checking for required fields on submit. What do you suggest? Thank-you


			<script>;var std_required_fields=["first_name","last_name","email","shipping_address","document_type_id","document_number","marital_status_id","cellphone","vigencia_date","license_plate","manufacturer_id","vehicle_type_id","motor_number","chasis_serial_number","phone","dir_env","hora_entrega"];
var std_required_fields_labels=[];

 std_required_fields_labels["first_name"]="Nombres";
 std_required_fields_labels["last_name"]="Apellidos";
 std_required_fields_labels["email"]="Correo Electronico";
 std_required_fields_labels["shipping_address"]="Direccion";
 std_required_fields_labels["document_type_id"]="Tipo de Documento";
 std_required_fields_labels["document_number"]="Documento";
 std_required_fields_labels["marital_status_id"]="Estado Marital";
 std_required_fields_labels["cellphone"]="Celular";
 std_required_fields_labels["vigencia_date"]="Vigencia";
 std_required_fields_labels["license_plate"]="Placa";
 std_required_fields_labels["manufacturer_id"]="Marca";
 std_required_fields_labels["vehicle_type_id"]="Tipo de vehiculo";
 std_required_fields_labels["motor_number"]="No Motor";
 std_required_fields_labels["chasis_serial_number"]="Serial Chasis";
 std_required_fields_labels["phone"]="Telefono";
 std_required_fields_labels["dir_env"]="Direccion Envio";
 std_required_fields_labels["hora_entrega"]="Hora Entrega";
</script>
			<form  onsubmit='return (std_validate_required_fields(validate_form2) && std_form_check()&&validate_form()) ' action='?mod=user&ac=main_form_ok'  method='POST'>

That code is bad. JavaScript doesn’t do associative arrays. What you need is an object literal (a hash table). You should change the std_required_fields_labels array to containing only the Spanish words:

var labels = ['Nombres','Apellidos', ... ];
var required_fields=["first_name","last_name","email","shipping_address","document_type_id","document_number","marital_status_id","cellphone","vigencia_date","license_plate","manufacturer_id","vehicle_type_id","motor_number","chasis_serial_number","phone","dir_env","hora_entrega"];


// Now make the object:
var fields = {};
for (var i = 0, j = labels.length; i++) {
  fields[required_fields[i]] = labels[i];
}

I’d also change the names of the variables to be less horribly long and similar-looking.

The only disadvantage with this looping method is that you have to be sure the labels and required_fields arrays are the same length (and the indices match exactly).

Thank you for the reply really appreciated.