You must understand that @Section
is a blade tag. Blade tags are processed inside PHP. Also, the blade syntax does not accept the parameter onload
as you want.
Also, either on HTML/JS you can't use onload
as you want.
You have two alternatives:
1 - Put a script tag after the section:
@section('content')
<!--PAGE CONTENT...-->
<div>
<h1>Something...</h1>
<select name="sel"></select>
</div>
<script>
// Note that this function must have been declared before
// this script tag, otherwise it will log an error:
// "Uncaught ReferenceError: MyFunction is not defined"
MyFunction();
</script>
@endsection
In this solution, the function will be called right after the browser loads this piece of html, but other parts of the html may not be loaded yet.
2 - Put a script tag watching for the load
event on document:
<script>
$(document).load(function() {
MyFunction();
});
</script>
The advantage of this method is that it will only be called after the entire page being loaded, so the order of the <script>
tags doesn't matters (except that the jquery call must be after the jquery script tag.