Looking for a code snippet: forms etc.

J

January Weiner

Hello,

I am looking for a code snippet that would help me improve my web page. I
have a limited javascript understanding, so that I will hopefully
be able to implement an idea if someone sketches the outline of the
solution.

Here is my problem: I have a cgi (Perl) that creates a form. In the form,
there is a popup menu showing a number of databases. The information about
this databases resides in a text config file, is being read by the script
and processed; that is, the popup menu is dynamically created by the
script. The script also reads a longer description of the databases from
the config file.

I would like to have the following behaviour: when the user selects a
database, the respective description appears in a div element somewhere
close by.

Thanks in advance for any ideas,

Cheers,
j.

--
 
P

Peter Michaux

Hello,

I am looking for a code snippet that would help me improve my web page. I
have a limited javascript understanding, so that I will hopefully
be able to implement an idea if someone sketches the outline of the
solution.

Here is my problem: I have a cgi (Perl) that creates a form. In the form,
there is a popup menu

An HTML "select element"

showing a number of databases. The information about
this databases resides in a text config file, is being read by the script

I'm assuming you mean JavaScript here as opposed to server-side
script.

and processed; that is, the popup menu is dynamically created by the
script. The script also reads a longer description of the databases from
the config file.

I would like to have the following behaviour: when the user selects a
database, the respective description appears in a div element somewhere
close by.

Below is a rough sketch that might help you get going.

Peter


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

<html lang="en">
<head>

<title>page</title>

<script type="text/javascript">

var databases = {
one: 'a <b>description<\/b>',
two: 'another description'
}

function showBlurb() {
var dbName = document.forms.dbForm.elements.dbSelect.value;
var blurbDiv = document.getElementById('blurbDiv');
blurbDiv.innerHTML = (dbName ? databases[dbName] : '');
}

// in case of browser's form autofill feature
window.onload = function() {
showBlurb();
};
</script>

</head>
<body>

<form name="dbForm" action="#" onsubmit="return false;">

<p>
<select name="dbSelect" onchange="showBlurb()">
<option value="">Select a database</option>
<option value="one">db one</option>
<option value="two">db two</option>
</select>
</p>

</form>

<div id="blurbDiv"></div>

</body>
</html>
 

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
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top