Reputation: 29
How to make a certain buttom be clicked on the load of the page?
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$("#submit").click(function() {
$("#submit").click();
});
</script>
</head>
<body>
<form action="Untitled-9.php" method="post">
<input type="text" name="name" value="dsa"/>
<input type="submit" name="submit" value="Register" />
</form>
<?php
$name = $_POST['name'];
echo $name;
?>
</body>
This is the code I have and I want when the page is loaded to press the button "Register" automatically
Upvotes: 1
Views: 13154
Reputation: 1
<script>
function aclick(){
document.getElementById("submit").click();
}
</script>
<body onLoad="aclick();">
<form action="name.php" method="post" >
<p >
<label>Email</label><br />
<input type="text" name="number" value="<?php echo $row['Mobileno']; ?>" /><br />
<label>Message</label><br />
<textarea name="msg"> </textarea><br /></p>
<input type="submit" name="submit" value="For Old Student Next to Reciepent" style="background-color:#006; color:#FFF;" id="submit" />
</form>
</body>
Upvotes: 0
Reputation: 6000
<?php if ($_POST["name"] == "") { ?>
<script type="text/javascript">
$(document).ready(function() {
$("input[name=submit]").click();
});
</script>
<?php } else {
echo $_POST["name"];
} ?>
Upvotes: 4
Reputation: 6564
<script type="text/javascript">
$(function(){
$("#submit").trigger('click');
});
</script>
would work as others have also suggested
you could also use
<script type="text/javascript">
$(function(){
$("form").submit();
});
</script>
Upvotes: 0
Reputation: 477
<script>
$(document).ready(function() {
$("#submit").click();
});
</script>
and put the id at:
<input type="submit" name="submit" value="Register" id="submit/>
Upvotes: 1