Ich habe ein kleines Problem mit jquery ... Ich habe ein Formular mit Standard 2 Felder, wenn eine der 2 leer ist die Schaltfläche zum Senden aus. Es funktioniertjquery Fehler mit überprüfen, ob leeres Formular
Aber ich füge auch eine "+" Taste, mit der Sie Textfelder hinzufügen, funktioniert es auch. Aber die Kontrolle dieser Felder funktioniert nicht, wenn nichts in der Sendetaste noch aktiv ist.
hier ist mein Code:
<table class="form-table" id="customFields">
<tr valign="top">
<th scope="row"><label for="customFieldName1">Question</label></th>
<div class="input-field col s12">
<td>
<input type="text" class="" id="customFieldQuestion" name="customFieldName[]" value="test" placeholder="Question"/>
<input type="text" class="" id="customFieldReponse" name="customFieldValue[]" value="test" placeholder="Reponse"/>
<a href="javascript:void(0);" class="remCF">Supprimer</a>
</td>
</div>
</tr>
</table>
<a href="javascript:void(0);" class="btn waves-effect waves-light btn-large" id="addCF" >+</a>
<button class="btn waves-effect waves-light btn-large" form="formfaq" type="submit" id="go" name="go">
Envoyer<i class="material-icons right">send</i>
</button>
</form>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-3.2.1.js"></script>
<script>
$(document).ready(function(){
$("#addCF").click(function(){
$("#customFields").append('<tr valign="top"><th scope="row"><label for="customFieldName1">Question</label></th><div class="input-field col s12"><td><input type="text" class="" id="customFieldQuestion" name="customFieldName[]" value="" placeholder="Question"/> <input type="text" class="" id="customFieldReponse" name="customFieldValue[]" value="" placeholder="Reponse"/> <a href="javascript:void(0);" class="remCF">Remove</a></td></div></tr>');
});
$("#customFields").on('click','.remCF',function(){
$(this).parent().parent().remove();
});
});
</script>
<script>
$(document).ready(function(){
$('#go').attr('disabled',false);
$('[id="customFieldQuestion"]').keyup(function(){
if($(this).val().length !=0)
$('#go').attr('disabled', false);
else
$('#go').attr('disabled',true);
})
$('[id="customFieldReponse"]').keyup(function(){
if($(this).val().length !=0)
$('#go').attr('disabled', false);
else
$('#go').attr('disabled',true);
})
});
</script>
Vielen Dank im Voraus für Ihre Hilfe
zuerst Ihre HTML aufzuräumen. Sie können nicht ein 'div' haben, das Ihren' td' einwickelt. Dann ändere die IDs, eine ID sollte eindeutig sein! Erst dann können wir Ihnen mit dem Rest helfen ... – LinkinTED