Results 1 to 8 of 8

Thread: Problem with <Button onclick=>

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70

    Problem with <Button onclick=>

    I am using VBScript and I have the following code on an ASP page.

    Code:
    <button onclick="Test;">Test</button>
    
    <%Sub Test%>
    <p>Hello</p>
    <%End Sub%>
    All I am trying to do is learn how to call a sub when the "Test" button is clicked. I have not been able to find an example of this.

    Any help would be greatly appreciated.
    Last edited by CT_Eagle; Aug 4th, 2004 at 12:44 PM.

  2. #2
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    <Script language="VBScript">
    Sub Test
    Document.Write("Hello")
    End Sub
    </script>
    <button onclick="Test">Test</button>

    Is there any reason that you can't use this?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70
    Thanks for the reply japshire.

    I already have some server side scripts on the page that are working correctly. If I add "<Script language="VBScript">", they no longer work.

    Any other thoughts?

  4. #4
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    I not sure that I understand where your point of failure is.
    Unfortunately I use asp.net and just a little vbscript, so I may not be very much help.

    Could you possibly provide some code.

    This works so I'm not sure exactly what you have.
    *****************************************************
    <html>
    <head>
    <Script type="text/vbscript">
    Sub Test1
    Document.Write("Hello from Test1!")
    End Sub
    </script>
    <title>Untitled Document</title>
    </head>
    <body>
    <%
    Dim i
    For i = 0 TO 5
    Response.Write("<font size=" & i & ">Pass" & i & "</font><br/>")
    Next
    %>
    <button onclick="Test1">Test1</button>
    </body>
    </html>

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70
    Thanks again for your response japshire. Your last response was successful in getting a sub to execute with the press of a button.

    I have the following code(including how you demonstrated how to get a button to execute a sub) on an ASP page:

    Code:
    <html>
    
    <head>
    
    <Script type="text/vbscript">
    
    Sub Test1
    	Document.Write("Hello from Test1!")
    End Sub
    
    </script>
    
    <title>CSTools - Organizations</title>
    
    </head>
    
    <body>
    
    <%
    Dim strConnect, strCompanyName
    Set objConn = Server.CreateObject("ADODB.Connection")
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& Server.MapPath("cstoolsdb.mdb")
    objConn.open strConnect
    strcompanyname = request.querystring("companyinfo")
    objRS.open "SELECT * FROM tblcompanies WHERE companyname = '" & strcompanyname & "'",objConn
    %>
    
    <%fillfields%>
    
    <%Sub fillfields%>
    <p align="center"><font size="6"><b><u><%=request.querystring("companyinfo")%></u></b></font></p>
    <p><font size=4><b>Catagory:</b>&nbsp;<%=objRS("catagory")%></font></p>
    <p><font size=4><b>ID:</b>&nbsp;<%=objrs("id")%></font></p>
    <p><font size=4><b>Billing Address:</b>&nbsp;<%=objrs("billingaddress")%>&nbsp;&nbsp;&nbsp;<b>Shipping Address:</b>&nbsp;<%=objrs("shippingaddress")%></font></p>
    <p><font size=4><b>City:</b>&nbsp;<%=objrs("city")%></font></p>
    <p><font size=4><b>State\Province</b>&nbsp;<%=objrs("stateorprovince")%></font></p>
    <p><font size=4><b>Postal Code:</b>&nbsp;<%=objrs("postalcode")%></font></p>
    <p><font size=4><b>Country:</b>&nbsp;<%=objrs("country")%></font></p>
    <p><font size=4><b>Modem:</b>&nbsp;<%=objrs("modemphoneno")%></font></p>
    <p><font size=4><b>Suffix:</b>&nbsp;<%=objrs("suffix")%>&nbsp;&nbsp;&nbsp;<b>Logon:</b>&nbsp;<%=objrs("logon")%>&nbsp;&nbsp;&nbsp;<b>Password:</b>&nbsp;<%=objrs("password")%></font></p>
    <p><font size=4><b>Navy Issues:</b>&nbsp;<%=objrs("navyissues")%>&nbsp;&nbsp;&nbsp;<b>Associate Membership:</b>&nbsp;<%=objrs("associatemembership")%></font></p>
    <%End Sub%>
    
    <%
    objRS.close
    set objRS = Nothing
    objConn.close
    set objConn = Nothing
    %>
    
    <button onclick="Test1">Test1</button>
    
    </body>
    
    </html>
    What I want the button to do is execute the sub "fillfields" when it is clicked. Any ideas on how to accomplish that would be greatly appreciated.

  6. #6
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32

    Question

    I'm not sure that you can do it that way.

    The reason I say that is everything in <%%> is being processed server side while your button onclick event is client side. As far as your button is concerned fillfields has never existed.

    I don't know that I would want to but if you keep everything client side then I would just place your displayed info in a form and process it like this.

    *****************************************************
    <html>
    <head>
    <Script type="text/vbscript">
    Sub Test1
    Document.myInfo.pCode.value = "77777"
    End Sub
    </script>
    <title>Untitled Document</title>
    <link href="testing.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <form name="myInfo">
    <label id="Label1">Postal Code:</label> <input name="pCode" style="Border: none;" type="text"><br/>
    <button onclick="Test1">Submit</button>
    </form>
    </body>
    </html>

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70
    "fillfields" is a sub that I have on the page itself. It is how I "populate" the page with the results from the database. It correctly gets the data from the database when the page is initially loaded. The problem is calling that sub when I change the customer name.

    I cannot keep everything client side because the database is located server side.

  8. #8
    Lively Member
    Join Date
    Aug 2004
    Posts
    70
    Hi CT_Eagle,


    did u re-submit/reload the page?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width