Reputation: 287
I am having an issue getting my below jquery to work. When I test it the form is not updating nor is the alert being triggered yet I have jquery on the page that works fine for a slider etc.I also do not see any errors in the console. My form has an id for form1 and my dropdown has an id of LoginTo
jQuery(document).ready(function() {
jQuery("#loginTo").change(function() {
var url = jQuery(this).children(":selected").text(); //get the selected option value
switch (url) {
case "Personal":
alert('Login Down For Maintenance');
jQuery("#form1").attr('action', 'https://fred.flinstone.com');
//changing action attribute of form
break;
case "Business":
alert('Business Login Down For Maintenance');
jQuery("#form1").attr('action', 'https://wilma.flinstone.com');
break;
default:
jQuery("#form1").attr('action', '#');
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="form1" method="post">
<div class="form-group">
<select id="loginTo">
<option value="" selected="selected" hidden="">Select account type</option>
<option valuw="Personal">Personal account</option>
<option value="Business">Business account</option>
</select>
</div>
<div class="form-group"><input name="myname" placeholder="Username" autocomplete="off"></div>
<div class="form-group"><input name="mypass" type="password" placeholder="Password" autocomplete="off"></div>
<div class="form-group"><input class="login__btn blue" type="submit" value="Sign in"></div>
<a class="login__btn" href="">Enroll Me Today</a>
</form>
Upvotes: 0
Views: 28
Reputation: 2619
Just use
$(this).val();
Instead of this children stuff
And take care you have a typo at the personal option „valuw“
Upvotes: 1