469,315 Members | 1,580 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Passing values from a page to a Form Field

Im fairly new on ASP and Javascript programming, I have read as much as I can to develop my website in a user friendly manner. Im 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 havent 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 Im trying to do is select the airport name and code from another ASP page. I have a javascript function in a .js file:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function passAirport(airport,formName,formField) {
  3.         var valuePath = eval("window.opener.document." + formName + "." + formField);
  4.         valuePath.value = airport;
  5.         window.close();
  6. }
You can view the 2 pages at ViajeroFrecuente dot NET/Compra.html. When you click in the B/W airplane image, another page (Aeropuertos_Spa.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 Im 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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <td align="right"><a href="javascript: MM_openBrWindow('Aeropuertos_Spa.asp?FldName=Origen','','scrollbars=yes,width=775,height=700')"><img src="/images/Icons/Aeropuerto.gif" alt="Seleccione Aeropuerto" width="16" height="16" border="0"></a>
And here is the code section on the Aeropuertos_Spa.asp page for the first airpot at the top.

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:passAirport('Aberdeen, SD (ABR)', 'travelrequest', '');" class="airport">Aberdeen, SD (ABR)</a><br>
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 !
Oct 6 '07 #1
7 2840
acoder
16,027 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. var valuePath = window.opener.document.forms[formName][formField];
The correct way to use code tags would be:
[CODE=javascript]
JavaScript code...
[/code]
Oct 6 '07 #2
I'll try that right away. Thanks for the other suggestions as well.
Keep you posted
Oct 6 '07 #3
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_openBrWindow('Aeropuertos_Spa.asp?FldName=Origen'..

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

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:passAirport('Aberdeen, SD (ABR)', 'travelrequest', XXX);" class="airport">Aberdeen, SD (ABR)</a><br>
I tried obviously the name of the variable but I get an error, as shown below:

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:passAirport('Aberdeen, SD (ABR)', 'travelrequest', FldName);" class="airport">Aberdeen, SD (ABR)</a><br>
  2.  
I also tried defining couple global variables and a function, but it did'nt resolve the problem

Expand|Select|Wrap|Line Numbers
  1. var formName; var fieldName
  2. function setFormElements(fn1,fn2) {formName=fn1; fieldName=fn2;}
  3.  
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
Oct 6 '07 #4
GOT IT.
I'm not sure if it is the most efficient way but this is how I solved:

Expand|Select|Wrap|Line Numbers
  1. <% FieldName = Request.QueryString("FldName") %>
  2. <a href="javascript:passAirport('Aberdeen, SD (ABR)', 'travelrequest', '<%=FieldName%>');" class="airport">Aberdeen, SD (ABR)</a><br>
  3.  
Oct 6 '07 #5
acoder
16,027 Expert Mod 8TB
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.
Oct 6 '07 #6
Thanks for helping me out. !!
Oct 6 '07 #7
acoder
16,027 Expert Mod 8TB
No problem. You're welcome.
Oct 7 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Paul | last post: by
1 post views Thread by Paul | last post: by
1 post views Thread by Iyigun Cevik | last post: by
2 posts views Thread by Ganesh | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.