Passing values from a page to a Form Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EyeHawk
    New Member
    • Oct 2007
    • 6

    Passing values from a page to a Form Field

    I’m fairly new on ASP and Javascript programming, I have read as much as I can to develop my website in a user friendly manner. I’m using javascript to pass some values in a Form, but is no working, I have tried to research, but being such a specific problem I haven’t being able to find any answers. Hope Somebody Can Help Me or put me in the right direction. Thanks in advance.

    I have a form and when clicking on an image all I’m trying to do is select the airport name and code from another ASP page. I have a javascript function in a .js file:

    [Code=javascript]

    function passAirport(air port,formName,f ormField) {
    var valuePath = eval("window.op ener.document." + formName + "." + formField);
    valuePath.value = airport;
    window.close();
    }[/code]

    You can view the 2 pages at ViajeroFrecuent e dot NET/Compra.html. When you click in the B/W airplane image, another page (Aeropuertos_Sp a.asp) opens, expecting you to select a city from the list. My goal is to pass the selected city/airport value back to the field (Origen) in the form on the previous page and close the window automatically.

    My form name is travelrequest, the first field that I’m trying to make it work is Origen, the one mark with “*” as it is a required field. Here is the code section on the Compra page:

    [Code=html]

    <td align="right">< a href="javascrip t: MM_openBrWindow ('Aeropuertos_S pa.asp?FldName= Origen','','scr ollbars=yes,wid th=775,height=7 00')"><img src="/images/Icons/Aeropuerto.gif" alt="Seleccione Aeropuerto" width="16" height="16" border="0"></a>[/code]

    And here is the code section on the Aeropuertos_Spa .asp page for the first airpot at the top.

    [Code=html]
    <a href="javascrip t:passAirport(' Aberdeen, SD (ABR)', 'travelrequest' , '');" class="airport" >Aberdeen, SD (ABR)</a><br>[/code]

    When I select teh value in the Aeropuertos_Spa .asp page it gives me the following error

    Can anybody please explain what I am doing wrong? Am I missing some variable definitions?
    PLEASE HELP !
    Last edited by acoder; Oct 6 '07, 05:31 PM. Reason: fixed code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    You've forgotten to pass the name of the form field. You're passing an empty string as the third parameter.

    No need to use eval. Change that line to:
    [CODE=javascript]var valuePath = window.opener.d ocument.forms[formName][formField];[/CODE]
    The correct way to use code tags would be:
    &#91;CODE=javas cript]
    JavaScript code...
    [/CODE]

    Comment

    • EyeHawk
      New Member
      • Oct 2007
      • 6

      #3
      I'll try that right away. Thanks for the other suggestions as well.
      Keep you posted

      Comment

      • EyeHawk
        New Member
        • Oct 2007
        • 6

        #4
        You are right I forgot to pass the FieldName. Since I'm doing the same process with different fields in the form, I should be able to use the variable FldName which I'm passing in the call and in my example has the value Origen. “….MM_openBrWin dow('Aeropuertos_Sp a.asp?FldName=O rigen'…..”

        How do I use that variable in the function call ? (instead of the XXX shown below)

        [CODE=html]
        <a href="javascrip t:passAirport(' Aberdeen, SD (ABR)', 'travelrequest' , XXX);" class="airport" >Aberdeen, SD (ABR)</a><br>[/CODE]

        I tried obviously the name of the variable but I get an error, as shown below:

        [CODE=html]
        <a href="javascrip t:passAirport(' Aberdeen, SD (ABR)', 'travelrequest' , FldName);" class="airport" >Aberdeen, SD (ABR)</a><br>
        [/CODE]

        I also tried defining couple global variables and a function, but it did'nt resolve the problem

        [CODE=javascript]
        var formName; var fieldName
        function setFormElements (fn1,fn2) {formName=fn1; fieldName=fn2;}
        [/CODE]

        If you try the online version, #1 is not working and 2-7 airports are working now, since I'm putting the field name, but as a string not as a variable.

        I also read online about the variable being located in indexSearch and other search mod components, but not sure what is it or how to use it..

        What would be the right way to use the value of FldName..?
        Thanks in advance for your help

        Comment

        • EyeHawk
          New Member
          • Oct 2007
          • 6

          #5
          GOT IT.
          I'm not sure if it is the most efficient way but this is how I solved:

          [CODE=html]
          <% FieldName = Request.QuerySt ring("FldName") %>
          <a href="javascrip t:passAirport(' Aberdeen, SD (ABR)', 'travelrequest' , '<%=FieldName%> ');" class="airport" >Aberdeen, SD (ABR)</a><br>
          [/CODE]

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Yes, that's the ASP way which is fine. In case you wanted the JavaScript way for some reason, try the location object's search property and parse it using the String object.

            Anyway, glad to hear that you got it working.

            Post again if you have any more questions.

            Comment

            • EyeHawk
              New Member
              • Oct 2007
              • 6

              #7
              Thanks for helping me out. !!

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                No problem. You're welcome.

                Comment

                Working...