?
Solved

updating form data from imageMap onClick()

Posted on 2003-03-06
8
Medium Priority
?
162 Views
Last Modified: 2008-03-06
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
Comment
Question by:marjKrug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:gator4life
ID: 8086574
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
 

Author Comment

by:marjKrug
ID: 8086671
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
 
LVL 5

Expert Comment

by:kasandra
ID: 8086719
Be aware that "id" is a reserved keyword in HTML! You should find a different vairable name, eg stationid


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
gator4life earned 400 total points
ID: 8086783
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
 
LVL 5

Expert Comment

by:kasandra
ID: 8099831
gator4life is correct about the newWindow() function. There is no point in duplicating code unnecessarily.
0
 

Author Comment

by:marjKrug
ID: 8101072
OK.Thanks for the tips!
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10097946
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 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