Ich versuche, die Aktion eines HTML-Formulars abhängig davon, welches Optionsfeld aktiviert ist, zu ändern. Ich versuche, jQuery dafür zu verwenden. Ich habe etwas Code und kann herausfinden, warum es nicht funktioniert. Kann mir bitte jemand helfen, dass dieser Code funktioniert?Ändern Formularaktion abhängig von Optionsfeldern
html:
<form name=loginForm id='login' action='' method='post'>
<legend>Login</legend>
<input type='text' name='email' maxlength="100" placeholder="Email"/>
<input type='password' name='password' maxlength="100" placeholder="password"/>
<div class="checkBoxGroup">
<label for="Employer">Employer</label>
<input type="radio" name="status" id='employer' value="employer">
</div>
<div class="checkBoxGroup">
<label for="Staff">Staff</label>
<input type="radio" name="status" id='staff' value="staff">
</div>
<input type='submit' name='Submit' value='Login' />
</form>
Javascript:
$(document).ready(function(){
$("input[name='status']").change(function(){
if($("#employer").prop("checked", true)){
$("#login").attr("action", "DB/employerVerification.php")
}
else{
$("#login").attr("action", "DB/userVerfification.php")
}
}
Könnte diese Frage sei eine Verdoppelung von [Frage] (http://stackoverflow.com/questions/5451600/jquery-to-change-form-action) –
Wenn du würdest Übermitteln Sie das Formular mit JS, Sie könnten diesen Teil komplett überspringen. oder verwenden Sie einfach document.getElementById ('Login'). Action = "newaction"; –