• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

updating form data from imageMap onClick()

Hi,here is my javascript problem:

I have 2 windows, say W1 and W2.

W1 is an opener for W2 and passes variables to W2.

W2 contains a listbox and checkboxes, with the number of checkboxes changing for each listbox selection. That is done by storing the variables passed to W2 in the opener (W1).

I now want to add an image Map to W1, with the clickable locations on the map enabling me to do the same as changing the selection in the listbox.

Hope that it is all making sense. Any suggestions??
0
marjKrug
Asked:
marjKrug
  • 2
  • 2
  • 2
  • +1
1 Solution
 
gator4lifeCommented:
Could you post some code concerning your exact question?  Such as, how are you storing the variables passed to W2, and how are you changing the number of checkboxes for each listbox?  Also, do you want the click on the image map to trigger the listbox in W2 to change, or do you just want the click to run similar functionality to the listbox selection without actually changing the listbox?  Some more information and some code would be very helpful.

gator4life
(chomp, chomp)
0
 
marjKrugAuthor Commented:
Hi,

The number of checkboxes is changed using an array of 0 and 1 which allows the checkbox selection to change according to the selection in the list.

The click on the map needs to change the listbox as well as the checkboxes.

Here is my code

In W1 (the opener) I have

function newWindow()
{
id = 0;
mywindow=open('datachoice.htm','myname','resizable=no,width=250,height=310');
mywindow.location.href = 'datachoice.htm';    if (mywindow.opener == null)
mywindow.opener = self;
}

with a button to generate W2 (the second window)
<input TYPE="button" VALUE="Show Stations" onClick="newWindow()">

In my second window I have in the header the script:
function makeWin(id)
{
datatype = new Array("curent","wave","waterlevel","ctd");
station = new Array()
// initialises available data within station (0 = boolean for no data)
station[0] = new Array(1,1,0,1)
station[1] = new Array(1,1,1,1)
station[2] = new Array(1,1,1,1)
station[3] = new Array(0,1,1,1)
station[4] = new Array(0,0,0,0)

// Put all the the form object in the output string and use document.write.output in main body of document
output = '<p><h3>Please click on a station to select data:</h3></p> ';
output+= '<form name="dataform">';
output+='<select name="stationchoice" onChange = "getId()" >';
// Creates list box for station selection
for (var j=0;j<station.length;j++)
{
if (j==id)
{output+='<option value=""+id+"" SELECTED>station '+ (j+1) +""+'</option>';}
else
{output+='<option value = ""+id+"" >station '+ (j+1) +""+'</option>';}
}
output+="</select><br>";
// Creates checkboxes for data selection
for (var j=0;j<datatype.length;j++)
{
if (station[id][j] == 1)
{output+='<p><input type = checkbox name = "datachoice">' +datatype[j];}
}

output+='<p><input type=button value="View Choice" onClick="viewChoice()" >';
output+='</form>';
return output;
}

function getId()
{
opener.id =document.dataform.stationchoice.selectedIndex;
location.href = "datachoice.htm";
}

in the body:
document.write(makeWin(opener.id));

-------------------
0
 
kasandraCommented:
Be aware that "id" is a reserved keyword in HTML! You should find a different vairable name, eg stationid


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gator4lifeCommented:
Another suggestion:

For this function -

function newWindow()
{
id = 0;
mywindow=open('datachoice.htm','myname','resizable=no,width=250,height=310');
mywindow.location.href = 'datachoice.htm';    if (mywindow.opener == null)
mywindow.opener = self;
}

Is there a reason why you immediately reload the same page into the popup window right after you create it?  Also, the opener to popup window "link" is created automatically in a browser through the window.open() method, so there is no need to explicitly perform this action.

In other words, you should simplify the newWindow() function to:

function newWindow() {

     stationId = 0;
     mywindow = open('datachoice.htm', 'myname', 'resizable=no,width=250,height=310');
}

And kasandra's suggestion was excellent.  You should never use a reserved DHTML keyword, such as "id", for a variable name.

gator4life
(chomp, chomp)
0
 
kasandraCommented:
gator4life is correct about the newWindow() function. There is no point in duplicating code unnecessarily.
0
 
marjKrugAuthor Commented:
OK.Thanks for the tips!
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: gator4life {http:#8086783}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now