Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Maintaining State of Variables with Dreamweaver

Posted on 2006-06-06
31
Medium Priority
?
365 Views
Last Modified: 2010-04-25
Hi all,
I have a page where users enter personal info. On that page there is a link to a page that interacts with google maps and sends a variable back to the first page. I want the first page to be refreshed, retaining any information the user had already entered, and also the posted data from the map page. Is there had easy way in Dreamweaver of doing this using session variables, etc? Any help would be much appreciated.
Thanks,
D
0
Comment
Question by:dereksheahan
  • 12
  • 9
  • 7
  • +2
30 Comments
 
LVL 8

Expert Comment

by:NovoNordisk
ID: 16846340
Is the data the users are entering being submitted into a form? If so then you can use
<%session("userdata") = request.form(userdata)%>
You could then display this again at any time providing the current window has not been closed.
0
 

Author Comment

by:dereksheahan
ID: 16846530
Hi NovoNordisk,
Yes it is being submitted through a form. So.. Are you saying I keep the first page open and have a pop-up page for the second page. Then on submitting the second page and POSTing back to the first I will be able to retreive the variables from the second page without refreshing it? I'm not very clear on exactly what method you think I should follow :)
D
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16846637
On page1 show the form.  This page posts the data to page2.

Page2 can then collect the values from the form and store them in a session variable (as per Novo's example), or in a cookie:  
    <% Response.Cookies("someValue") = Request.Form("someField") %>

Once the data has been collected, page2 can show it's usual data and perform its normal functions.  A link back to page1 is also provided here.

Page1 then summons back the values collected from page2.
    <input type="text" name="someField" value="<% Request.Cookies("someValue") %>" />
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16846650
Hi Derek,

So the user fills out a form which pops up Google Maps.   Writing those variables to a session is pretty easy (hand-coding, though).

How does Google Maps send the variable back?
0
 

Author Comment

by:dereksheahan
ID: 16846795
Hi guys,

>>>>>How does Google Maps send the variable back?
I have a script written that interacts with Google Maps and POST's the variables new_lat and new_long back to the main page (reg1,php).

Rouchie, I am correct in saying that the main page stays open all the time and when I click on the link to the second page it appears in a new window? Then on submit of this second page it closes the window and returns to the first page. The variables (new_lat and new_long) will then be stored in the correct places? Is this the method? Here is a link to the testing page on the server (http://www.reachateacher.ie/map/reg1.php) so ye can get a better idea. Follow the link to the "click here to exact address" to the map page and then back again. I think that will explain it better!
Cheers,
D
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16846950
Unfortunately you're using php, which means Jason's answer might be more suitable as I'm an ASP man, but I'm going to have a go...!

The easiest method would be a pop-up window that contains the map.  Then instead of posting back using php, you could just use javascript to make the values appear in the main form page.  The popup window could then automatically close down when the values are in correctly.  This also allows the user to change their coordinates as many times as they choose.

The map (popup) window would have a submit button that did something like this

<input type="button" value="Submit" name="Submit" onClick="parent.window.TextBoxName.value='6.34543634634634'" />

where the numeric value is what you pull from the map.  You might need a small JS function to put both values in.  See what Jason recommends in the PHP world though first... ;-)
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16847017
Okay I'm feeling generous - here's my stab at the map page.  Function goes in the <head> section.  Button replaces the current submit button.  Just make sure the window is open in a popup activated by the link on the form page.

function populatesValues() {
   parent.window.main.document.form1.label11.value = document.form1.new_lat.value;
   parent.window.main.document.form1.label12.value = document.form1.new_lon.value;
   window.close();
}

<input type="button" value="Submit" name="Submit" onClick="return populatesValues;'" />
0
 

Author Comment

by:dereksheahan
ID: 16847145
Thanks Rouchie,
It giving me this error when I check it in the FF javascript console.
Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: http://www.reachateacher.ie/map/sfliveaddpt.php


//Line: 255 output.innerHTML = "<form name=form1 method=post action=reg1.php><table border=0>"+
"<tr><td></td><td align=left><input name=new_lat type=hidden id=new_lat value=" + point.y + "></td><td"+
"<tr><td></td><td align=left><input name=new_lon type=hidden id=new_lon value=" + point.x + "></td></tr>"+
"<tr><td>If you are happy with the point you have chosen click submit</td></tr>"+
"<tr></td><td align=left><input type=button value=Submit name=Submit onClick=return populatesValues; /></td></tr></table></form>";//Line 255


I hope I have the map page coming up as a child page. I changed the target to "_blank" and that brings up a new window. Is this correct?
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16847229
Okay give this one a go...

function populatesValues() {
   parent.document.getElementByID("label11").value = document.form1.new_lat.value;
   parent.document.getElementByID("label12").value = document.form1.new_lon.value;
   window.close();
}

The button stays the same as my previous example.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16847243
>> I changed the target to "_blank" and that brings up a new window. Is this correct?

Not too sure.  To be sure. change target="myChildWindow"
That also stops people hitting the map link more than once and spawing loads of windows with the same content inside.
0
 

Author Comment

by:dereksheahan
ID: 16847282
Still the same error I'm afraid Rouchie.
Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: http://www.reachateacher.ie/map/sfliveaddpt.php
Line: 264

Cheers,
D
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16847474
Rouchie,

Nice little script :)

Derek,

If Google is posting to a page on your server, you can add the $_POST array to your session.  The problem is how to do this to get the form to redisplay.

I would consider breaking this up into several steps in order to get the variables into the session easier.  
0
 

Author Comment

by:dereksheahan
ID: 16847510
Hi Jason,
How might I go about breaking this up?
Cheers,
D
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16847591
Not totally sure...

1) Have them input their address.  Write values to DB or Session.
2) Post values to Google Maps (could use $_GET to send it as URL) to generate lat and long
3) Google Maps posts lat and long to a PHP page on your site that adds them to a session or array
4) Display new page on your site with the form completely populated by recordset or session vars

Or am I missing the point of the question again?

0
 

Author Comment

by:dereksheahan
ID: 16847666
No you're not missing the point. I only want to write the values to the DB once all of the page is filled in. There is one piece of info I didn't put in that might be relevant. I need the user to select their native town first from a drop-down on the first page. This value will then be passed to the child-page (map page) and the map will automatically zoom to the corresponding location. I have all of this working in another test script but haven't integrated the two together yet.
So.. basically when the form is completed it would probably be better if it was send to the DB once( this is the first page of a multiple details entry for a user so I guess I'll use this page to create PK for table).
 >>>2) Post values to Google Maps (could use $_GET to send it as URL) to generate lat and long
I don't need to post these values (lat, lon) to the google page, only back from it.
3) Google Maps posts lat and long to a PHP page on your site that adds them to a session or array
Yes, that would be great. I really liked Rouchie's idea on this because though javascript it would update even if the user clicks it twice and changes his/her mind.
Not really sure where to take it from here??
Thanks,
D
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16847711
>> I only want to write the values to the DB once all of the page is filled in

This is a stylistic difference only. Writing to the DB once or multiple times still nets you the same data in the end.  

>> So.. basically when the form is completed it would probably be better if it was send to the DB onc

Pull-down town form on a page by itself.  User selects town, posts to Google.  Google does something and posts data back to a page on your site.  All this page does is accept the Google data and process it to some PHP variable, session, array or table (any would work) and then displays the final form for the user with all the fields filled in.  Submit to table and done.

If this flow works for you, then the question becomes "what is Google sending back?"  Once that is established, the code should be pretty simple.
0
 

Author Comment

by:dereksheahan
ID: 16847756
As the "enter your location on a map" is optional for the user, I would like to avoid just having the pull-down town on a separate page if at all possible.

>>>>>"what is Google sending back?"
I have this part working already. If you test the page you'll see that the reg1.php returns from the map page with the Latitude and Longitude of the selected coordinates populated in the correct fields, like so "<?php echo htmlspecialchars($_POST['new_lat']);?>". If I wanted to have the drop-down for the towns on a separate page, your right it would be simple, indeed I would be finished already. Problem lies in opening a new page (map page) and getting the variables back from this page( which is done) while keeping the variables that the user has already entered on the first page (the bit I'm stuck on).
Hope I'm making sense,
D
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16848353
Okay, I get it now.

Unless you are willing to have the user submit the variables on the first page first (which solves everything), then you will need some javascript to pass stuff from one window to the nest.  Rouchie is on the best track...
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16849988
You guys have been busy!

I've been Googling the javascript error and I think the problem might be simpler than I imagined.  Well, I hope so anyway.  In your first form page you have code like this:

     Latitude:    <input type="text" name="textfield12" id="label11" value="" />
     Longitude: <input type="text" name="textfield13" id="label12" value="" />

I think the script is unhappy because the ID value and NAME value are different.  Try changing the source code to make them the same for the 2 boxes we need to manipulate:

     Latitude:    <input type="text" name="latitude" id="latitude" value="" />
     Longitude: <input type="text" name="longitude" id="longitude" value="" />

Then the script in the popup window can be changed to reference them using the new names:

function populatesValues() {
   parent.document.getElementByID("latitude").value = document.form1.new_lat.value;
   parent.document.getElementByID("longitude").value = document.form1.new_lon.value;
   window.close();
}

It might not work, but it is a step in the right direction.
0
 

Author Comment

by:dereksheahan
ID: 16850894
Hi Rouchie,
I'm afraid it still gives the same error :(
Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: http://www.reachateacher.ie/map/sfliveaddpt.php
Line: 264

Not sure what's going on with it really??
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16851568
Okay let's try again... :-)  Here's 3 ways to refer to the target fields in the parent window.  Give each one a try and let me know how you get on.

function populatesValues() {
   window.opener.document.getElementByID("latitude").value = document.form1.new_lat.value;
   window.opener.document.getElementByID("longitude").value = document.form1.new_lon.value;
   window.close();
}


or even this....

function populatesValues() {
   window.opener.document.form1.getElementByID("latitude").value = document.form1.new_lat.value;
   window.opener.document.form1.getElementByID("longitude").value = document.form1.new_lon.value;
   window.close();
}

or this...

function populatesValues() {
   window.opener.document.forms[0].getElementByID("latitude").value = document.form1.new_lat.value;
   window.opener.document.forms[0].getElementByID("longitude").value = document.form1.new_lon.value;
   window.close();
}
0
 

Author Comment

by:dereksheahan
ID: 16853945
Hi Rouchie,
No none of them are working either. It still gives the same error message on each in javascript console "Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: http://www.reachateacher.ie/map/sfliveaddpt.php
Line: 264"
It might have to do with another javascript function on the page interfering with it. I'll look into it a little more and maybe put a pointer in the javascript section?
Thanks,
D
0
 

Author Comment

by:dereksheahan
ID: 16856473
Hi Rouchie,
I've solved the above problem. All that was needed was to change the HTML text in the javascript call to
document.getElementById('output').innerHTML = "<form name=form1 method=post ......

The function still isn't working though. At least now in the javascript console it returns no errors (either on adding a marker or on clicking the submit button). When I click the submit it does nothing at all at the moment, should there be a this.close or something similar to close the page after the submit button is pressed also?
I really am at a loss as to why the javascript isn't functioning though
Thanks,
D
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16859210
Although you have solved the problem of the errors, I'm not sure that what you're doing is the correct way to solve this.  By altering innerHTML you are in effect re-writing a chunk of the page, rather than inserting values into objects that already exist.

After looking at the map page again, I realise that the submit button is actually written in javascript as well, rather than being a standalone html object.  I'm not sure how this effects the reliability, but I see that the javascript function we've put in isn't actually being called at all.

This line that makes the submit button appear:
"<tr></td><td align=left><input type=button value=Submit name=Submit  /></td></tr></table></form>";

needs to call the function when it is pressed:
"<tr></td><td align=left><input type=button value=Submit name=Submit onClick=\"populatesValues();\"/></td></tr></table></form>";

If this doesn't work, then I'd ask a moderator to close this question for you to get your points back, then repost in the javascript topic area.  Now that we have isolated the functionality down to javascript then those guys will be able to solve this problem in no time.
0
 

Author Comment

by:dereksheahan
ID: 16860867
Hi Rouchie,
Yeah no joy on that one either I'm afraid. I feel you deserve the points on it but if thats what you want you to do then I'll post it in the support section.
Thanks for all your help. I really appreciate it.
D
0
 

Author Comment

by:dereksheahan
ID: 16861379
Hi Rouchie,
So... I posted it in the JS section and you were right, they had it solved in minutes. Here's what they changed it to if interested:
Changed the function call to onClick=populatesValues();
and the function to:
window.opener.document.forms[0].latitude.value = document.form1.new_lat.value;
window.opener.document.forms[0].longitude.value = document.form1.new_lon.value;

Thanks again for your time,
D
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16866149
No objections
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16868156
No objections.

Damn I was close!  
Thanks for posting that feedback Derek - it's nice to know how the problem was finally resolved.  A learning experience for all of us I guess....!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16872112
Rouchie

Missed it by this ><  much.

J
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 16887171
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month21 days, left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question