1

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

1
  • 1
    just break the problem down: #1 how do I do something on page load; #2 how do I trigger a click; #3 drink, dance and rejoice. Commented Nov 27, 2012 at 22:49

5 Answers 5

4
<?php if ($_POST["name"] == "") { ?>

<script type="text/javascript">
    $(document).ready(function() {
        $("input[name=submit]").click();
    });
</script>

<?php } else {

    echo $_POST["name"];

} ?>
Sign up to request clarification or add additional context in comments.

6 Comments

if you don't set a callback parameter .click trigger a click event... api.jquery.com/click for reference
this works perfect but once it load the page it just continiusly load it again and again.. just dont stop to load the page again and again
is the page perhaps Untitled-9.php?
that's because when you trigger the click event, you submit the form
why you want trigger that click right after the document ready?
|
2

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

1 Comment

He needs to add an ID attribute to the submit button for this to work.
1
<script>
    $(document).ready(function() {
      $("#submit").click();
  });
</script>

and put the id at:

<input type="submit" name="submit" value="Register" id="submit/>

Comments

0
<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>

Comments

0

<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.