Bobi Qnkov
Bobi Qnkov

Reputation: 29

Click button on loading the page

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

Answers (5)

Azhar Alam
Azhar Alam

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

Bruno
Bruno

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

owenmelbz
owenmelbz

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

Boris Gappov
Boris Gappov

Reputation: 2493

Try this: $("#submit").trigger('click');

Upvotes: 2

Alexandru Chelariu
Alexandru Chelariu

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

Related Questions