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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if eof in DB, direct onclick to one function otherwise other 1

Status
Not open for further replies.

gradinumcp

IS-IT--Management
Apr 6, 2005
85
US
Hi there..I have an asp page where I have a SQL statement which is checking if there is a record in the database. There is also a table on this page which has a button with an onclick javascript. What I want to do is that if there is no record in the database, the onclick should go to Function1, if not Function2.

Any clues...

Heres the code:

'Check if record exists in servicing export table

mySQL = "SELECT * FROM ServicingExportFields where loannum='"&request("Loannum")&"'"
Set RecordCounter = Con.Execute( mySQL )

-----------------------------------------------------------

<td><input type="text" name="WareHouseNumber"><input type="button" Name='Stamp' value='Stamp' onclick="Function('value1', 'value2', 'value3');"></td>

-----------------------------------------------------------


<script language="JavaScript1.2"><!--
function Function1(value1, value2, value3){
alert("Record Not Present");
window.open("UpdatePage1.asp?value1="+value1+"&value2="+value2+"&value3="+value3, target="_main");
}
// --></script>

-----------------------------------------------------------

<script language="JavaScript1.2"><!--
function Function2(value1, value2, value3){
alert("Record Present");
window.open("UpdatePage2.asp?value1="+value1+"&value2="+value2+"&value3="+value3, target="_main");
}
// --></script>
 
Code:
if RecordCounter.EOF and RecordCounter.BOF then
'call function1
else
'call function2
end if

-DNG
 
Here's an example:
Code:
<%
mySQL = "SELECT   * FROM ServicingExportFields where loannum='"&request("Loannum")&"'"
Set RecordCounter = Con.Execute( mySQL )
dim blah = RecordCounter.RecordCount;

dim clickHandler
if blah = 0 then
   clickHandler = "function1('value1', 'value2', 'value3')"
else
   clickHandler = "function2('value1', 'value2', 'value3')"
end if
%>


<input type="button" Name='Stamp' value='Stamp' onclick="<%=clickHandler%>">

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Thanks DotNetGnat....but this function calling should happen only when the button is clicked. And should I change to functions to ASP function rather than javascript functions?
 
And should I change to functions to ASP function rather than javascript functions?

You cannot run a server side (asp) function from the click of a button w/o submiting or loading a new page. Well... not entirely true - you could use AJAX to get this effect, but then you're still gonna have to use javascript to get the AJAX to fire, so javascript is your best bet.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
yep..change the functions to ASP functions instead of Javascript functions if possible...currently you are trying to mix server-side and client-side scripts...

-DNG
 
Thanks Kaht..I tried your method. Just a question, can I send the value of the Stamp field to the clickhandler like

onclick="<%=clickHandler('DM01', '<%=RS("loannum")%>', document.Page1.WareHouseNumber<%=RS("loannum")%>.value) %>">

Similarly in function 1 and function 2?
 
Kaht and DNG--the code is erroring up on me. Just want to make sure in kaht's code, the function1 and function 2 are ASP functions or javascript functions? If ASP functions--any clues on the syntax of the function and how to call it--sorry I am a newbie:(
 
Just a question, can I send the value of the Stamp field to the clickhandler like

Not the way you've got posted:
Code:
onclick="[!]<%[/!]=clickHandler('DM01', '[!]<%[/!]=RS("loannum")%>', document.Page1.WareHouseNumber<%=RS("loannum")%>.value) %>">

As you can see you have 2 ASP break tags in a row - this is not valid. If you want to append an extra variable in the middle, use the & to concatenate the strings - something like this:
Code:
onclick="<%=[!]"[/!]clickHandler('DM01', '[!]" &[/!] RS("loannum") [!]& "[/!]', document.Page1.WareHouseNumber[!]" &[/!] RS("loannum")[!] & "[/!].value)[!]"[/!]%>"

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Just want to make sure in kaht's code, the function1 and function 2 are ASP functions or javascript functions?

They are client side javascript functions that are called from the client's machine when the button is clicked. You can test this yourself by doing a view-source on the page after it has loaded - you should see the reference to the function name there in the code - an ASP function will never reveal itself to the client because it runs server side.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Still Error--its just going to page cannot be displayed---am I missing something:

'Check if record exists in servicing export table

mySQL = "SELECT * FROM ServicingExportFields where loannum='"&request("Loannum")&"'"
Set RecordCounter = Con.Execute( mySQL )

dim blah = RecordCounter.RecordCount;

dim clickHandler
if RecordCounter.eof then
clickHandler = "Function1(tbl, loannum, val)"
else
clickHandler = "Function2(tbl, loannum, val)"
end if

-----------------------------------------------------------

onclick="<%="clickHandler('DM01', '" & RS("loannum") & "', document.Page1.WareHouseNumber" & RS("loannum") & ".value)"%>"

-----------------------------------------------------------

<script language="JavaScript1.2"><!--
function Function1(tbl, loannum, val){
alert("Not In Servicing");
window.open("UpdateAccountingWHNUM.asp?tbl="+tbl+"&loannum="+loannum+"&val="+val, target="_main");
}
// --></script>

-----------------------------------------------------------

<script language="JavaScript1.2"><!--
function Function2(tbl, loannum, val){
alert("In Servicing");
window.open("UpdateAccountingWHNUM.asp?tbl="+tbl+"&loannum="+loannum+"&val="+val, target="_main");
}
// --></script>
 
ok..... things are starting to get sloppy because you're not showing the full scope of the problem each time. I created a variable (server side - asp) with the name of the function to be called (client side - javascript). This server side variable was declared clickHandler - it was a string that basically showed the exact syntax of how the function needed to be called client side. Then, this string would be outputted to the client, so it knew the name of the function that it needed to call client side.

Here's where this happens:
Code:
clickHandler = "Function1(tbl, loannum, val)"

In your second post, you were passing arguments to the clickHandler string, so I assumed that was the name of the function you wanted called client side, so I put the quotes around it so it would be passed to the client.

here's where this happens:
Code:
"clickHandler('DM01', '" & RS("loannum") & "', document.Page1.WareHouseNumber" & RS("loannum") & ".value)"

Well.... you have the string called clickHandler server side, but then you're not using it correctly when you try to pass the function name to the client. What you need to pass to the client is exactly this:
Code:
onclick="<%="clickHandler[s]('DM01', '" & RS("loannum") & "', document.Page1.WareHouseNumber" & RS("loannum") & ".value)[/s]"%>"

That way, once the code gets to the browser, this is what it will see:
Code:
onclick="Function1(tbl, loannum, val)"
-or-
onclick="Function2(tbl, loannum, val)"

depending on how many rows were returned from the query. Now.... if you need to fill out the parameters passed to that function (tbl, loannum, val), you need to do it at the time that the string is generated, not as it's being passed to the client.
Code:
if RecordCounter.eof then
     clickHandler = "Function1(tbl, loannum, val)"
else
     clickHandler = "Function2([!]fill out parameters here[/!])"
end if

And finally, it's a bit rude to reply in red text "Is my syntax to call the functions wrong?" after not getting a response for 15 mins. That's about the same as replying in all caps or using boldface, it insinuates that you are angry about something - and in this case I interpreted that you are angry that you hadn't gotten a reply yet (which I was busy, not that it even matters - I don't HAVE to help you). Just remember that the help you get here is free and to come across as demanding will likely get you ignored in the future by myself and most likely others.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Thanks Kaht..I'll take a deeper look into the code as you explained it quite well. Iam sorry if my red text showed I was angry--i just thought becoz of my long code...probably my words were being missed out so I wrote in red....never ment to be angry at all--on the contrary I am thankful for all the help you are giving me...its truly a learning experience. Sorry again and i'll get back to you in a few mins after trying the code again:) Thanks:)
 
Hey Kaht...I tried the code as you told me and and it says 'clickHandler' is undefined on the line onclick="<%="clickHandler"%>" :(
 
whoops, I messed up, the quotes shouldn't be around clickHandler, I should have put the line thru them as well above:
Code:
 onclick="<%=clickHandler%>"

Assuming you set the variable above to "function1..." or "function2...", it should be defined.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Hey Kaht--that kind of works--however whether there is a record of not...it always hits function 2 and never function 1...any clue why it would do that?
 
Maybe cause you're checking against RecordCounter.eof to determine the function. In my first post I showed to check if the recordcount was equal to 0 or not. I'm not sure why you changed it to eof, so you might wanna check that out.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Hey Kaht---I had to change that coz it was erroring up on me. Now my code is:


'Check if record exists in servicing export table

mySQL = "SELECT * FROM ServicingExportFields where loannum='"&request("Loannum")&"'"
Set RecordCounter = Con.Execute( mySQL )

dim clickHandler

if RecordCounter.eof then
clickHandler = "Function1('DM01', '" & RS("loannum") & "', document.Page1.WareHouseNumber" & RS("loannum") & ".value)"

else
clickHandler = "Function2('DM01', '" & RS("loannum") & "', document.Page1.WareHouseNumber" & RS("loannum") & ".value)"

end if
-----------------------------------------------------------

<td><input type="text" name="WareHouseNumber<%=RS("loannum")%>" class=fields>&nbsp;<input type="button" Name='Stamp' value='Stamp' class=fields4 onclick="<%=clickHandler%>"></td>

-----------------------------------------------------------

<script language="JavaScript1.2"><!--

function Function1(tbl, loannum, val){
alert("Not in Database")
window.open("UpdateAccountingWHNUM.asp?tbl="+tbl+"&loannum="+loannum+"&val="+val, target="_main");
}
// --></script>

-----------------------------------------------------------

<script language="JavaScript1.2"><!--
function Function2(tbl, loannum, val){
alert("In Database")
window.open("UpdateAccountingWHNUM.asp?tbl="+tbl+"&loannum="+loannum+"&val="+val, target="_main");
}
// --></script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top