Need a start for this project

D

Dropstengel

Hi,

Although I'm very familair with C++ programming, I'm having some problems
coding up a piece of JavaScript for my sister in law.

The problem is the following:

From a website I need to select from a combobox one of the items x(1)..x(n)
When selected a new window must pop up that describes more details about the
selected items x(i).
Items in the combobox must be created from objects that also describe the
details.

Here starts my problem...I know how to define objects x(1)..x(n) and how to
create a combobox from it.
But how to start a new page that shows the details. In fact, how can I
access the objects that exist in the first window from the second window?

This is the first question...I have plenty more..but I think when I
understand this piece I might find out all the answers myself.

Please help (I feel ashamed that I don't know the answer as a pretty
experienced C++ programmer)

Frank
 
L

Lee

Dropstengel said:
Here starts my problem...I know how to define objects x(1)..x(n) and how to
create a combobox from it.
But how to start a new page that shows the details. In fact, how can I
access the objects that exist in the first window from the second window?

Here's one solution. The entire HTML of the second window is the value
returned by the toHTML value defined for the selected Object in the first
window. If nothing else, note that global objects and functions in the first
window can be accessed from the second window via the "opener" reference to the
first window.

<html>
<head>
<script type="text/javascript">

function genericToHTML(){
var HTML=[
"<html><head><title>",this.name,"</title></head>",
"<body><table><tr><td>Name</td><td>",this.name,
"</td></tr><tr><td>Capitol</td><td>",this.capitol,
"</td></tr><tr><td>Statehood Date</td><td>",this.statehood,
"</td></tr><tr><td>Nickname</td><td>",this.nickname,
"</td></tr></table></body></html>"
];
return HTML.join("");
}

function popup(obj){
// "The opener...toHTML()" expression in the window.open() argument
// is evaluated in a different scope, so we create a global reference
// to the selected Object. Simple, if distasteful.
globalSelectedObject=obj;
window.open("javascript:eek:pener.globalSelectedObject.toHTML()",
"popupWindow",
"width=400,height=200,resizable,scrollbars").focus();
}

var myObject = { name : "Arizona",
capitol : "Phoenix",
statehood : "February 14, 1912",
nickname : "The Grand Canyon State",
toHTML : genericToHTML
};
</script>
</head>
</body>
<form>
<input type="button" onclick="popup(myObject)" value="Arizona">
</form>
</body>
</html>
 
D

Dropstengel

Lee said:
Dropstengel said:
Here starts my problem...I know how to define objects x(1)..x(n) and how to
create a combobox from it.
But how to start a new page that shows the details. In fact, how can I
access the objects that exist in the first window from the second window?

Here's one solution. The entire HTML of the second window is the value
returned by the toHTML value defined for the selected Object in the first
window. If nothing else, note that global objects and functions in the first
window can be accessed from the second window via the "opener" reference to the
first window.

<html>
<head>
<script type="text/javascript">

function genericToHTML(){
var HTML=[
"<html><head><title>",this.name,"</title></head>",
"<body><table><tr><td>Name</td><td>",this.name,
"</td></tr><tr><td>Capitol</td><td>",this.capitol,
"</td></tr><tr><td>Statehood Date</td><td>",this.statehood,
"</td></tr><tr><td>Nickname</td><td>",this.nickname,
"</td></tr></table></body></html>"
];
return HTML.join("");
}

function popup(obj){
// "The opener...toHTML()" expression in the window.open() argument
// is evaluated in a different scope, so we create a global reference
// to the selected Object. Simple, if distasteful.
globalSelectedObject=obj;
window.open("javascript:eek:pener.globalSelectedObject.toHTML()",
"popupWindow",
"width=400,height=200,resizable,scrollbars").focus();
}

var myObject = { name : "Arizona",
capitol : "Phoenix",
statehood : "February 14, 1912",
nickname : "The Grand Canyon State",
toHTML : genericToHTML
};
</script>
</head>
</body>
<form>
<input type="button" onclick="popup(myObject)" value="Arizona">
</form>
</body>
</html>

Thanks,
However, if I apply this to my problem I get something different. My
sources:

<html>
<title>Hogeschool NTI - Opleidingen</title>
<head>

<script language="JavaScript">

alleOpleidingen = new Array(2)
alleOpleidingen = new Array(
new opleiding
( "Informatie- en management",
"HAVO/VWO/MBO of 21+ toets",
"3",
"2475",
"168"),
new opleiding
( "Bedrijfskundige Informatica",
"",
"",
"",
"")
)


function toonOpleiding()
{
var HTML =[
"<html><head></head><body>",
"<b>Naam:</b> " , this.naam , "<br>" ,
"<b>Vooropleiding:</b> " , this.vooropleiding , "<br>",
"<b>Studieduur:</b> " , this.studieduur , "<br>",
"<b>Lesgeld per jaar:</b> " , this.lesgeld , "<br>",
"<b>Studiepunten:</b> " , this.punten , "<br>",
"</body></html>"
];
return HTML.join("");
}



function opleiding(naam,vooropleiding,studieduur,lesgeld,punten)
{
this.naam = naam
this.vooropleiding = vooropleiding
this.studieduur = studieduur
this.lesgeld = lesgeld
this.punten = punten
this.toonOpleiding = toonOpleiding
}



function opleidingList(inForm)
{
var n=alleOpleidingen.length
inForm.selOpl.options[0] = new Option("Kies een opleiding")
for (var i=0; i < n; i++)
{
inForm.selOpl.options[i+1] = new Option(alleOpleidingen.naam)
}
inForm.selOpl.size=n+1
}


function openAanvraagScherm(opl)
{
if( (opl > 0) && (opl <= alleOpleidingen.length) )
{
g = alleOpleidingen[opl-1];
window.open(
"javascript:eek:pener.g.toonOpleiding",
"popupAanvraagWindow",
"width=400,height=200,resizable,scrollbars").focus();
}
}

</script>
</head>


<body onLoad="opleidingList(frmOpl)">
<form
name="frmOpl">
<select
name="selOpl"
onChange="openAanvraagScherm(selectedIndex)"
</select>
</form>
</body>
</html>



What's wrong?
Frank
 
D

Dropstengel

Andrew Thompson said:
When a 'pretty experienced' C++, Java, etc.
programmer (whatever) kid's themselves that
Javascript is a 'simple' language.
..always amuses me.


Cool, just do no lose site of the fact that
Javascript is a subtle and rich language that
offers great possibilities to the (web) user,
if only the progammer can apply it to best use.

And this is coming from a 'Java' programmer aho
has yet to fully grasp those JS subtleties..

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

:)
May be I'm feeling I'm going back 10 years while typing plain ascii in a
text file and try to see if it works....
I miss a good Development Environment.....but probably they exist for JS.
Why is my sister in law assuming that I can do JS because I'm a programmer?
Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top