Reputation: 597
i have a input like this "
<input type='button' name='osx' value='Demo' class='osx demo' runat="server" />
that when i click on this , it runs a jQuery plugin. now i want to call this input's click event on my page load, in fact i want to run it's plugin at page load, so i use this code :
<script>
$("document").ready(function () {
window.getElementById("osx").click();
});
</script>
but when i run my page , i get this error :
Line: 16 Error: Object doesn't support property or method 'getElementById'
i done all of your answers but non of them worked for me!!! here in my page's code :
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<link type='text/css' href='css/osx.css' rel='stylesheet' media='screen' />
<script>
$("document").ready(function () {
document.getElementById("osx").click();
}
</script>
</head>
<body>
<div id='container'>
<div id='content'>
<div id='osx-modal'>
<input id='osx' type='button' name='osx' value='Demo' class='osx demo' runat="server" />
or <a href='#' class='osx'>Demo</a>
</div>
<!-- modal content -->
<div id="osx-modal-content">
<div id="osx-modal-title" dir="rtl">
OSX Style Modal Dialog</div>
<div class="close">
<a href="#" class="simplemodal-close">x</a></div>
<div id="osx-modal-data">
<h2>
Hello! I'm SimpleModal!</h2>
<p>
SimpleModal is a lightweight jQuery Plugin which provides a powerful interface for
modal dialog development. Think of it as a modal dialog framework.</p>
<p>
SimpleModal gives you the flexibility to build whatever you can envision, while
shielding you from related cross-browser issues inherent with UI development..</p>
<p>
As you can see by this example, SimpleModal can be easily configured to behave like
an OSX dialog. With a handful options, 2 custom callbacks and some styling, you
have a visually appealing dialog that is ready to use!</p>
<p>
<button class="simplemodal-close">
Close</button>
<span>(or press ESC or click the overlay)</span></p>
</div>
</div>
</div>
</div>
<script type='text/javascript' src='js/jquery.simplemodal.js'></script>
<script type='text/javascript' src='js/osx.js'></script>
</body>
</html>
where am i do wrong?
Upvotes: 4
Views: 31289
Reputation: 11
Try this
$(document).ready(function () {
document.getElementById("<%=btnProvideContactInfo.ClientID%>").click();
});
Upvotes: 1
Reputation: 1750
<script>
$(document).ready(function () {
$("input[name=osx]").click();
});
</script>
OR Without jQuery
<script>
document.addEventListener('DOMContentLoaded',function(){
document.getElementById("osx").click();
});
</script>
Upvotes: 5
Reputation: 411
<script>
$(document).ready(function () {
document.getElementById("osx").click();
});
</script>
or
<body onload="document.getElementById('osx').click();">
with id="osx" added to your input element
Upvotes: 10
Reputation: 3170
Why it did not work for you
getElementById
is not a method of window object. It is a method of document
object, so use document.getElementById("osx").click();
and your input
tag should have id='osx'
.
you were using $("document")
. Dont put quotes around document
in $(document)
.
How to solve it
Add id
attribute to your input element -
<input id='osx' type='button' name='osx' value='Demo' class='osx demo' runat="server" />
And if you like to use jQuery, then -
$(document).ready(function () {
$("#osx").click();//using id selector
}
otherwise using document.getElementById
$(document).ready(function () {
document.getElementById("osx").click();
}
Upvotes: 0
Reputation: 132
I think you place id in input type.
<input type='button' name='osx' value='Demo' class='osx demo' id='osx' runat="server" />
Upvotes: 0
Reputation: 371
use jQuerys .trigger()
<input type='button' id='osx' value='Demo' class='osx demo' runat="server" />
this is jQuery code..
<script>
$("document").ready(function () {
$('#osx').trigger('click');
});
</script>
Upvotes: 0
Reputation: 1146
You can use "trigger":
<script>
$(function () {
$(".osx").trigger("click");
});
</script>
Upvotes: 0
Reputation: 28763
Try with .trigger()
like
<script type="text/javascript">
$("document").ready(function () {
$(".osx").trigger('click');
});
</script>
And you didnt have the id
atribute.So add it and try
<input type='button' name='osx' value='Demo' class='osx demo' id='osx' runat="server" />
Upvotes: 0