user3731042
user3731042

Reputation: 39

Change click.function() to an onload

I'm using the following script that works fine when I do the click function, but I need to change it so it will happen when the Web page loads. I could not find the answer to my problem searching through stackoverflow, so I would appreciate any help from anyone on how to change it.

<script language="JavaScript">
    $(function() { //run on document.ready
      $("#current_sessioner").click(function() { //this occurs when select 1 changes
        $("#sessioner").val($(this).val());
      });
    });
</script>

Upvotes: 1

Views: 62

Answers (2)

MCGRAW
MCGRAW

Reputation: 817

document.addEventListener('DOMContentLoaded', function(){
   $("#sessioner").val($('#current_sessioner').val());
}, false);

Upvotes: 1

Bertrand Marron
Bertrand Marron

Reputation: 22210

Simply move it out of the click handler.

$(function () {
  $("#sessioner").val($('#current_sessioner').val());
});

Upvotes: 3

Related Questions