Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 5th, 2008, 04:54 PM
Newbie
 
Join Date: Oct 2008
Location: earth
Age: 24
Posts: 4
Default Calling javascript function from asp

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. function enb() {
  3. document.form1.send.disabled=false
  4. }
  5. </SCRIPT>
i need to call the above function in asp page and inside if /else
i try

javascript:enb()

and

enb()

and

call enb()

all didnt work can any one give me advice

Last edited by jhardman; October 6th, 2008 at 06:38 PM. Reason: put code in code tags. please note button marked #
Reply
  #2  
Old October 6th, 2008, 10:39 AM
Newbie
 
Join Date: Oct 2008
Posts: 12
Default

The problem is that you have no event to fire the function.

Try..
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. test = 1
  3. %>
  4.  
  5. <html>
  6. <head>
  7.  
  8. <SCRIPT LANGUAGE="JavaScript">
  9. function enb() {
  10. document.form1.send.disabled=true;
  11. }
  12. </SCRIPT>
  13. </head>
  14. <body 
  15. <%
  16. IF test=1 THEN
  17. %>
  18. onLoad="enb()"
  19. <%
  20. ELSE
  21. %>
  22.  
  23. <%
  24. END IF
  25. %>
  26. >
  27.  
  28. <form name="form1" id="form1" action="test.asp?action=called" method="GET">
  29.  
  30. <input type="button" name="send" id="send" value="send" />
  31.  
  32. </form>
  33.  
  34. </body>
  35. </html>

Last edited by jhardman; October 6th, 2008 at 06:40 PM. Reason: put code in code tags. please note button marked #
Reply
  #3  
Old October 6th, 2008, 06:36 PM
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Age: 32
Posts: 2,374
Default

Snester is right, and this is actually a common goof. You see, ASP is executed on the server and javascript is executed on the browser. Snester's approach of adding the javascript function call to the body onload event (conditionally, using asp) is the best way to solve this problem.

Jared
Reply
  #4  
Old October 7th, 2008, 08:33 AM
Newbie
 
Join Date: Oct 2008
Location: earth
Age: 24
Posts: 4
Default

Thanks for your answer about calling tha javascript but im still in same problem i need to enable the send button in the page after checking the captcha text without submitting all the form content so i need to call the javascript function from server side
Reply
  #5  
Old October 7th, 2008, 04:36 PM
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Age: 32
Posts: 2,374
Default

You can't. Javascript is executed on the client, not on the server. I know of no captcha that is processed with javascript. There is not an active connection between the browser and the server, the form has to be submitted after the captcha is filled in order for the server to see what the user entered. It might be possible to do something like this with ajax, but then you would be asking in the wrong forum.

Jared
Reply
  #6  
Old October 7th, 2008, 05:36 PM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 924
Default

If I've understood you correctly then you could 'disable' the button by checking the condition that decides whether or not to display it and if it's true write the html that displays it. If it's not true then you can display an image that looks like the disabled button instead.

Not sure if this sorts your problem out as i'm answering this in a hurry but I hope so :-)

Dr B
Reply
  #7  
Old October 8th, 2008, 05:58 PM
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Age: 32
Posts: 2,374
Default

DrB, I think he is saying he has a "captcha" or "text capture to block automated submissions" and he wants to check it against a value on the server while neither submitting the whole form nor putting the correct answer anywhere on the page (he doesn't want the javascript function to have the answer). Using just ASP you would need to submit the whole form to check the "captcha". It is possible that this sort of thing could be handled with Ajax, but I definitely don't know how to do that.

Jared
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles