...

View Full Version : Popup query



djfenom
09-24-2003, 10:45 AM
I'm using the following code to create a popup window which has a form located inside it:

var win1 = new Object;
function pop(page,top,left,width,height,resize,scroll,fullscreen){
closepop();
win1 = eval("window.open('" + page + "','popup','top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",resizable=" + resize + ",scrollbars=" + scroll + "');")
}
function closepop(){
if (win1.closed == false)
{win1.close();}
}

<a href="javascript: pop('location-form.html','15','15','400','400','no','yes');">

To get to the form you click on a region on a map. What I need is for each region on the map, I need the dropdown select field to be selected on the region that was clicked on.

<select name="select">
<option value="Yorkshire" selected>Yorkshire</option>
<option value="Cheshire">Cheshire</option>
<option value="Lincolnshire">Lincolnshire</option>
<option value="Durham">Durham</option>
<option value="Shropshire">Shropshire</option>
</select>

For example, if a person clicked on Cheshire, then the popup form would appear and under the dropdown menu, Cheshire would be selected.

Hope somebody can help.

Thanks in advance.

Chris

cheesebag
09-24-2003, 04:20 PM
Omitted some key details. Is there a different form for each region on the map? If so, how is that data being passed to the server?

This is more easily done server-side, particularly if you're running script there anyway, but it could be handled at the browser by passing the region as querystring data, and setting the select onload.

That is the worst pop-up opener ever. :eek:

djfenom
09-24-2003, 04:24 PM
There is only one form for each region on the map.

I was thinking more of an onload, but don't know how to implement it.

Hope you can help, you can change the popup code if you like. :)

Thanks

Chris

cheesebag
09-24-2003, 04:27 PM
djfenom....
ME: Is there a different form for each region on the map?
YOU: There is only one form for each region on the map.I think you missed my point....;)

djfenom
09-24-2003, 04:29 PM
Ok, there is only one form, you click on any region on the map and you get the same form, rather than do 20 forms with the dropdown menu selection different, I thought this could be achieved in javascript.

Thanks again

Chris

cheesebag
09-24-2003, 04:40 PM
You've mentioned 'map' several times. Are we talking 'image map'?

Think about it: for a program to 'know' which region has been clicked on, there has to be some mechanism for determining where the clickpoint was. Setting the drop-down is the easy part.

Might want to look into client-side image maps. Are you using a graphics program?

djfenom
09-24-2003, 04:43 PM
I am using a geographical map of the UK, which is split up into regions using an imagemap, each region can be clicked to open the popup form.

cheesebag
09-24-2003, 05:11 PM
Hoped you might be set up that way. :)

Try this: add a querystring to each link in the map, consisting of

1) question mark
2) 'region='
3) name of region

So.....<area href="location-form.html?region=Yorkshire" target="putItThere" onclick="return deadCenter(this.href)".....>

Then:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

function setSelectByValue()
{
var Qstr = unescape(location.search.substring(1));
var region = Qstr.split('region=')[1];
var opt, i = 0, oSelect = document.form_name.region;
while (opt = oSelect.options[i++])
if (opt.value == region)
{
opt.selected = true;
break;
}
}

onload = setSelectByValue;

</script>
</head>
<body>
<form name="form_name">
<select name="region">
<option value="Yorkshire" selected="selected">Yorkshire</option>
<option value="Cheshire">Cheshire</option>
<option value="Lincolnshire">Lincolnshire</option>
<option value="Durham">Durham</option>
<option value="Shropshire">Shropshire</option>
</select>
</form>
</body>
</html>

The pop-up code:


var putItThere = null;
var chasm = screen.availWidth;
var mount = screen.availHeight;
var wd = chasm*.9; // percentage of screen width occupied by pop-up
var ht = mount*.8; // percentage of screen height occupied by pop-up

function deadCenter(url) {
putItThere = window. open(url,'putItThere','width='+wd+',height='+ht+',
left='+((chasm-wd-10)*.5)+',top='+((mount-ht-25)*.5)+',scrollbars,status,titlebar');
if (putItThere & !putItThere.closed)
putItThere.focus();
return false;
}

You'll need to remove the spaces before 'open' and the linefeeds after ,height='+ht+', inserted by this editor.

djfenom
09-25-2003, 09:02 AM
Thank you so much, this is perfect.

Cheers.

Chris



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum