Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/01/2011, 12:31
alvaroarbey
 
Fecha de Ingreso: diciembre-2010
Mensajes: 2
Antigüedad: 13 años, 4 meses
Puntos: 0
Pregunta Como capturo el value del select en jquery??

Este es el formulario que tengo

<div id="dialog-formCiudad" title="REGISTRA UNA CIUDAD">
<p class="validateTips">Todos los Campos son Requeridos</p>

<form>
<fieldset>
<label for="iddepartamento">Nombre del Departamento</label>
<select name="iddepartamento">
<option value="1">Uno</option>
<option value="2">Dos</option>
<option value="3">Tres</option>
</select>
<br>
<label for="nameciudad">Nombre de la Ciudad</label>
<input type="text" name="nameciudad" id="nameciudad" class="text ui-widget-content ui-corner-all" /><br><br>
</fieldset>
</form>
</div></div>
<div class="demo">
<!-- Este boton nos permite abrir un cuadro de dialogo en el cual se ingresaran los campos necesarios para el registro -->
<button id="create-userCiudad">REGISTRO CIUDAD</button>
</div>

Necesito enviar el value de ese select a esta funcion!


$(function() {
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
$( "#dialog:ui-dialog" ).dialog( "destroy" );

//nombre de los post
var nameciudad = $( "#nameciudad" ),
iddepartamento = $( "#iddepartamento" ),
allFields = $( [] ).add( nameciudad ).add( iddepartamento ),
tips = $( ".validateTips" );

function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}

function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "El largo del " + n + " debe contener caracteres entre " +
min + " y " + max + "." );
return false;
} else {
return true;
}
}

function checkRegexp( o, regexp, n ) {
if ( !( regexp.test( o.val() ) ) ) {
o.addClass( "ui-state-error" );
updateTips( n );
return false;
} else {
return true;
}
}

$( "#dialog-formCiudad" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
//Boton Registrar del Dialogo
"Registrar": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );

bValid = bValid && checkLength( nameciudad, "nombre de la Ciudad", 3, 20 );
bValid = bValid && checkRegexp( nameciudad, /^[a-z]([a-z_])+$/i, "El nombre de la Ciudad debe contener solo letras" );
// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/

if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + nameciudad.val() + "</td>" +
"<td>" + iddepartamento.val() + "</td>" +
"</tr>" );

//aqui debo capturar los datos del formulario
//en JS se capturan con #
var nombreciudad = $("#nameciudad").val();
var departamento = $("#iddepartamento").attr('value') ;
alert(departamento);

//aqui es donde debes generar un post a php
//alert("mande el post");


$.post('registrociudad.php', { name: (nombreciudad), iddeldepartamento: departamento },function(data)
{ $('#respuesta').html(data);
alert(data);
});



$( this ).dialog( "close" );
}
},
Cancelar: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});

$( "#create-userCiudad" )
.button()
.click(function() {
$( "#dialog-formCiudad" ).dialog( "open" );
});
});


Esta es la funcion JS, necesito saber dónde y cómo capturo el value del select!
POR FAVOR AYUDA!!
Y GRACIAS!