Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Canastota NY
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with passing asp values to javascript

    I have a main form that is calls (from a button event) the below code to read a database and retreive 4 or 5 fields. I want to return those fields from withing the ASP script back to the form
    <HTML>
    <head>
    <META http-equiv="Content-Style-Type" content="text/css">
    <script language="JavaScript">
    function putLabel(desc){
    if (opener && !opener.closed){
    opener.document.createpob.desc.value=desc;
    window.close();
    }
    }
    </script>
    </head>
    <BODY BGCOLOR=#FFFFFF TEXT=#330099 LINK=#CC0000 LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" basefont size="1" color="green">
    <FORM id="Display" name="Display" method="post" action="itemdisplay2.asp">
    <%
    sub Displayitem ()
    If request.form("Item") <> "" then
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    cfile= "\\128.1.1.232\plus\inv/inv/" & request.form("ITEM")
    set wfile=fs.openTextFile(cfile,1,FALSE)
    counter=0
    do while not wfile.AtEndOfStream
    counter=counter+1
    singleline=wfile.readline
    If counter = 3 then
    itemdesc=singleline
    response.write ("Item Desc = " & itemdesc & "<br>")
    end If
    If counter = 28 then
    oldcost=singleline
    response.write ("Old Cost = " & oldcost & "<br>")
    end If
    If counter = 30 then
    lastord=singleline
    response.write ("Last Order = " & lastord & "<br>")
    end If
    If counter = 34 then
    taxcode=singleline
    response.write ("Tax Code = " & taxcode & "<br>")
    end If
    If counter = 36 then
    gledger=singleline
    response.write ("G.Ledger = " & gledger & "<br>")
    end If
    loop
    wfile.close
    set fs=nothing
    set wfile=nothing
    end if
    End Sub
    %>
    <Input type="text" name="Item" value="" id="item">
    <Input type="submit" value="display info">
    <!INPUT TYPE='BUTTON' VALUE='Use Values' onClick="javascriptutLabel(<%=itemdesc%>)">
    <INPUT TYPE='BUTTON' VALUE='Close Window' onClick="window.close()">
    </FORM>
    <%Displayitem%>

    </BODY>
    </HTML>

    I can't get the asp field value (I'm trying just DESC first) - into the script to return - help anyone?

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    You have to remember that all the ASP code is processed before the HTML is sent to the browser to display. The way you have your code, you're calling the subroutine for your ASP code AFTER the line where you ask for the variable from your ASP. Also, is this suppose to submit the form to itself? Because you have a Request.Form call in your ASP that refers to an input on the page itself. Request.Form only grabs values from a form that has already been submitted. If the form submits to itself, then that set is ok, except for the subroutine being called after the line where you attempt to use a variable from your ASP code.

    -Shane

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Canastota NY
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank for your reply - what I am really trying to do is this

    I have a form "createpo" that is collecting a lot of data for a transaction submit. One of the text boxes is for inputting a product ID. Before the form is actually submitted, the user wants to be able to use the value in this text box to open a new window, retreive information from a database (like product name, cost), and populate other text boxes on the original form THEN submit. The best I have been able to do is open a new window where they can SEE the fields - this code was an attempt to return the values to the other form.....

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Alright, I don't think I can really help you here. That is much more involved and I'm not advanced enough to really give you the proper help in this without testing the code myself, which I def. don't have time to do, hehe. Good luck and hope someone here can help you.

    -Shane

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @rgbjag,
    Does it have to open in a new window? I was thinking that when you loaded the page, you could have some asp code that would write out a JavaScript function with all the pre-filled data stored in arrays. Then when the user typed/selected an id, you could fire off a JavaScript function that would pre-fill the form with the values in the array based on the id typed/selected.

    --NeoCool

  • #6
    New Coder
    Join Date
    Jan 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I always cheat

    Like this:

    hxxp://Localhost/test.asp?123=something%20here&456=something%20else

    <%
    ' Assign variables
    var123 = Request.QueryString("123")
    var456 = Request.QueryString("456")

    ' Output to JavaScript
    Response.Write("<SCRIPT type='text/JavaScript'>" & vbcrlf)
    Response.Write(" var j123 = '" & var123 & "';" & vbcrlf)
    Response.Write(" var j456 = '" & var456 & "';" & vbcrlf)
    Response.Write("</SCRIPT>")
    %>

    <HTML>
    <BODY OnLoad=something()>
    123 = <%= var123 %>,&nbsp 456 = <%= var456 %>
    </BODY>
    </HTML>

    <SCRIPT type='text/JavaScript'>

    function something()
    {
    alert("123 = " + j123 + "\n" + "456 = " + j456)
    }

    </SCRIPT>


  •  

    Posting Permissions

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