Updating Form Elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leatherman77
    New Member
    • Jun 2007
    • 5

    #1

    Updating Form Elements

    Hi, I am trying to develop a form. What I need to do is to write data into the form elements when the form is first loaded. This is then made available for the user to modify data. I believe the function I require is SetValue, but I cannot figure out which object it comes from and how to use it correctly. Nor can I find any documentation on how to use it. Can anyone help. Thanks in advance

    Steve
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Leatherman77. Welcome to TSDN!

    Are you looking to update form elements on a web page using JavaScript?

    Comment

    • Leatherman77
      New Member
      • Jun 2007
      • 5

      #3
      Thank you for the welcome. I am actually doing most of this in VBScript, although there is some Javascript in there. I use VBScript to interface with my SQL, which is working fine. Then I want to populate my form with the data from the database, so that it can then be amended by the user. I am using some Javascript to react to a submit button, which then redirects to a new page. The most efficient solution would be the best :)

      Comment

      • Leatherman77
        New Member
        • Jun 2007
        • 5

        #4
        I don't want to end up running back here every time I get stuck, but perhaps someone could explain why I cannot get the following code to work:
        [code=vb]
        <%@ LANGUAGE="VBSCR IPT" %>
        <%
        Public sub validate
        vbMsgBox "Hi"
        end sub

        sub vbMsgBox(msg)
        Response.Write( "<" & "script language=VBScri pt>")
        Response.Write( "MsgBox """ & msg & """<" & "/script>")
        end sub

        %>
        <HTML>
        <TITLE>Office Response</TITLE>
        <%validate%>
        <FORM NAME="Details" method = POST>
        <INPUT TYPE=button value = Submit OnClick="valida te()">
        </FORM>
        </HTML>
        [/code]

        [Please use CODE tags when posting source code. Thanks! --pbmods]

        I can call validate from anywhere else within the page, but it will not allow me to run it when I click the button. I get a Type Mismatch error. Thanks again.

        Steve

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by Leatherman77
          I can call validate from anywhere else within the page, but it will not allow me to run it when I click the button. I get a Type Mismatch error. Thanks again.
          VBScript is a server-side language, whereas JavaScript is client-side.You can create JavaScript code using VBScript, which the browser will then evaluate when the page loads. You can also set up an AJAX call to a web page that executes VBScript. But the two technologies cannot directly interact.

          I'm going to go ahead and move your thread to the VB forum where you will receive more relevant exposure.

          Comment

          • Leatherman77
            New Member
            • Jun 2007
            • 5

            #6
            Thank you, sorry for the breach of etiquette. I have used the more acceptable solution to solve my second problem. I have moved my code out of a function and into a different ASP page and I call that ASP from my FORM declaration. This appears to be working ok now. Incidentally the vbMsgBox function above I found on another site does allow client-side scripting that will display a message box for the user.

            I am still stuck on my original issue however. Can anyone tell me how to write data into a form element using ASP? Cheers

            Comment

            • Leatherman77
              New Member
              • Jun 2007
              • 5

              #7
              In response to my own question:

              Code:
              Sub UpdateInput(Form,Name,Val)
              Response.Write("<" & "script language=javascript>") 
              Response.Write("document. " & Form & "." & Name & ".value='" & Val & "'") Response.Write("</script>")
              End Sub
              I thought other people might find my solution useful. What I do is to use a VBScript function to send Javascript to the client-side that updates the form.

              :)

              Comment

              Working...