I am using this code to get the current url of the page in to div, when I click on submit button. I am not getting how to call function onclick. How to do this?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>localhost</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="spn_url"></div>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
This question is related to
javascript
jquery
html
JS
$(function () {
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
$("#submit").click(function () {
alert('button clicked');
});
});
html
<input id="submit" type="submit" value="submit" name="submit">
try this:
$('form').submit(function(){
// this function will be raised when submit button is clicked.
// perform submit operations here
});
try this ..
<input type="submit" value="submit" name="submit" id="submit">
$(document).ready(function () {
$('#submit').click(function () {
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
});
});
Try this:
HTML:
<input type="submit" value="submit" name="submit" onclick="myfunction()">
jQuery:
<script type="text/javascript">
function myfunction()
{
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
}
</script>
Source: Stackoverflow.com