So I have code like this:
<script language="javascript">
$(function(){
function hellothere(strng){
showalert(strng);
}
function showalert(showit){
alert(showit);
}
});
</script>
<input type="button" onclick="hellothere('hi');" value="jquery"/>
When I click on the button though, it throws a javascript error (Object expected).
I have also tried the following but they also throw javascript errors (Object does not support this property).
<input type="button" onclick="$.hellothere('hi');" value="jquery"/>
and
<input type="button" onclick="$.fn.hellothere('hi');" value="jquery"/>
What am I missing?
UPDATE: This is what’s happening, to clarify alittle.
I have a button:
<input type="button" class="mybutton" value="jquery"/>
On page load, I assign an onclick event to the button with the $():
$(function(){
$(".mybutton").click(function(){
//Do some stuff
mybuttoncallback(dataprocessed);
});
function senditoff(finaldata){
//send the data off
}
});
So this button is on a couple pages but is does different things with the data that’s processed. So the ‘mybuttoncallback’ is a javascript method that is local to the page itself since different pages may handle the data differently.
function mybuttoncallback(thedata){
//process the data
senditoff(hereitis);
}
The ‘senditoff’ method is in the jquery code since all the pages send it off the same way.
I would prefer not to move anything out of the $() because many pages would have to change.
(The ‘senditoff’ method is the ‘hellothere’ method from the previous example.)
So have can the javascript method call the jquery ‘senditoff’ method??
If you really need to extend the jQuery object, try this: