javascript - Change url of button depending on input text -
i have created form fields button.
i need url of button change depending on data entered in last name field. booking reference field not effect url
example: user enters "john" in last name field button should have url: http://www.john.com
example: user enters "henry" in last name field button should have url: http://www.henry.com
<form> <p style="margin-bottom: -10px; font-size: 12px;">*required fields</p><br> <input type="text" placeholder="last name *" name="lastname"> <input type="text" placeholder="booking reference *" name="ref"> <a href="http://localhost:8888/ek/booking/" class="btn btn-info" role="button">retrieve booking</a> </form>
you can use blur
event on lastname
achieve this,
$('input[name=lastname]').on('blur', function(){ debugger var lastname = $('input[name=lastname]').val() //check if last name there if(lastname.length !== 0){ var link = 'http://www.'+ lastname +'.com'; $('.btn.btn-info').attr('href',link); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <p style="margin-bottom: -10px; font-size: 12px;">*required fields</p><br> <input type="text" placeholder="last name *" name="lastname"> <input type="text" placeholder="booking reference *" name="ref"> <a href="http://localhost:8888/ek/booking/" class="btn btn-info" role="button">retrieve booking</a> </form>
Comments
Post a Comment