Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I call a function used OnClick without the click? 1

Status
Not open for further replies.

jofarrell

Programmer
Mar 21, 2001
178
US
Being new to ASP this may sound stupid, but I have a javascript code that clears my ASP form on the click event of a button. I am just now seeing that it would be nice to be able to call it not only on the click of "Clear Form" but also when there is no data to fill into a dynamically created table and I just want the shell (Same as what my clearform does).

Is this possible?

Joanne


 
Yes -- try this out:

First, you'll need to determine if there is no data. Easy enough, right? So let's make a variable called noData -- values 0 or 1 (1 = no data, 0 = there is data). This is obviously going to be set in your server side scripting.

Then, we'll do two things:
(1) set a global javascript variable to hold that value, so you can get at it client-side
(2) write another javascript function to check the value of that variable and then either call or don't call your function that you were (are) calling onClick of your button:

<script language=javascript>
var noData = <%=noData%>; //notice the same names for the variables, but one is ASP and one is JS

function checkForNoData(){
if (noData){
onClickFunction();
}
}
</script>

We'll just evaluate noData as if it was a boolean variable (which, in essence, it is). We'll call checkForNoData() body onLoad

<body onLoad=&quot;checkForNoData();&quot;>

And there you have it.

:)
Paul Prewett
penny.gif
penny.gif
 
heh You are too good ... its amazing how complicated something as easy as a timesheet can get *grin*


But its actually starting not only look good but be functional *grin* which is a point I never thought it would get to.

Thanks again Paul

Joanne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top