Ich habe die folgende Form:Nicht Lesen .val() einige Eingänge
<div class="col-md-12">
<div class="inLabel go-bottom hvz-street-smaller">
<div class="inLabelDiv">
<input type="text" name="locStreetAddress" id="locStreetAddress" placeholder="Straße" class="hvz-form-control triggerAddress">
<label for="locStreetAddress">Straße</label>
</div>
</div>
<div class="inLabel go-bottom hvz-number-smaller">
<div class="inLabelDiv">
<input type="text" name="locNumber" id="locNumber" placeholder="HNr." class="hvz-form-control triggerAddress">
<label for="locNumber">HNr.</label>
</div>
</div>
</div>
<div class="col-md-12">
<div class="inLabel go-bottom hvz-zip-smaller">
<div class="inLabelDiv">
<input type="text" name="locZip" id="locZip" placeholder="Postleitzahl" class="hvz-form-control triggerPrice triggerAddress" value="">
<label for="locZip">Postleitzahl</label>
</div>
</div>
<div class="inLabel go-bottom hvz-city-smaller">
<div class="inLabelDiv">
<input type="text" name="locCity" id="locCity" placeholder="Stadt" class="hvz-form-control triggerAddress" value="">
<label for="locCity">Stadt</label>
</div>
</div>
<div class="inLabel go-bottom hvz-country-smaller">
<div class="inLabelDiv">
<input type="text" name="locCountry" id="locCountry" placeholder="Land" class="hvz-form-control triggerAddress" value="Deutschland">
<label for="locCountry">Land</label>
</div>
</div>
</div>
Für jeden .triggerAddress
Eingang ich dies tun:
$(document).on('change', '.triggerAddress', function (event) {
var street = $('#locStreetAddress').val();
var number = $('#locNumber').val();
var zip = $('#locZip').val();
var city = $('#locCity').val();
var country= $('#locCountry').val();
var address = street + ' ' + number + ', ' + zip + ' ' + city + ', ' + country;
if(street !== '' && number !== '' && zip !== '' && city !== '' && country !== ''){
//..DO STUFF
}else{
console.log(address);
}
});
Unfortunatley, var street
und var number
nie Wert bekommen? Doing console.log(street)
oder console.log($('#locStreetAddress').val())
gibt eine Leerzeile für Straße und Nummer zurück. Alle anderen Felder funktionieren wie vorgesehen.
Was fehlt mir?
// EDIT Finale Bearbeiten/Cleanup Es ist ein Problem mit featherlight.js Ich verwende: https://github.com/noelboss/featherlight/issues/122 Für die Zukunft:/Eingänge lesen richtig zu aktualisieren, machen persist: true
und alles wie vorgesehen funktioniert.
Ihr Code absolut einwandfrei funktioniert: https://jsfiddle.net/5kppvrj8/. Überprüfen Sie Ihre Konsole auf Fehler und stellen Sie sicher, dass Sie nicht mehrere Elemente mit dem gleichen Attribut 'id' haben. –
Überprüft, es sind keine Duplikate. Selbst das Umbenennen hilft nicht. Ich werde es noch einmal überprüfen. – PrimuS
Bitte beziehen Sie sich auf https://gist.github.com/brandonaaskov/1596867 –