Reputation: 53
I am designing a JSP page with form action.
<form action="" method="post">
Username: <input type="textfield" name="username" />
Country : <input type="textfield" name="country" />
Url : <input type="textfield" name="Url" />
<input type="submit" value="Submit" />
</form>
I want to set the user given URL value in form action when I click the Submit button and redirect to that URL. How can I achieve this?
Upvotes: 4
Views: 8426
Reputation: 17839
This can work pretty well
<form action="" method="post" id="myForm">
Username: <input type="text" name="username" />
Country : <input type="text" name="country" />
Url : <input id="url" type="text" name="Url" />
<button onclick="doStuff();">Submit</button>
</form>
<script>
function doStuff(){
$('#myForm').attr('action', $('#url').val());
$('#myForm').submit();
}
</script>
Don't forget to include the JQuery api's in your code:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
Upvotes: 3