Calling javascript function from asp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samercontrol
    New Member
    • Oct 2008
    • 4

    Calling javascript function from asp

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function enb() {
    document.form1.send.disabled=false
    }
    </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; Oct 6 '08, 05:38 PM. Reason: put code in code tags. please note button marked #
  • snester
    New Member
    • Oct 2008
    • 12

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

    Try..
    Code:
    <% 
    test = 1
    %>
    
    <html>
    <head>
    
    <SCRIPT LANGUAGE="JavaScript">
    function enb() {
    document.form1.send.disabled=true;
    }
    </SCRIPT>
    </head>
    <body 
    <%
    IF test=1 THEN
    %>
    onLoad="enb()"
    <%
    ELSE
    %>
    
    <%
    END IF
    %>
    >
    
    <form name="form1" id="form1" action="test.asp?action=called" method="GET">
    
    <input type="button" name="send" id="send" value="send" />
    
    </form>
    
    </body>
    </html>
    Last edited by jhardman; Oct 6 '08, 05:40 PM. Reason: put code in code tags. please note button marked #

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      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

      Comment

      • samercontrol
        New Member
        • Oct 2008
        • 4

        #4
        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

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          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

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            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

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              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

              Comment

              Working...