Connecting Tech Pros Worldwide Forums | Help | Site Map

How to re-print values from combobox selection

Mtek
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi,

We have a combo box on our page, which gets populated via a MySQL
Query in PHP.

What we want to do is to print the values on the page in a table that
correspond the to selection from the combo box without a page refresh.

I assume that I'll need to query ALL the needed values from the
database and store them in an array This can be done in PHP. Drawing
the combo box is not a problem. But, once a selection is made, how do
I print the values to the page?

I'm assuming an 'on change' events needs to be attached to the box,
but, it is not a form, so, there would not be any submit to the
server. How do we print the values from the selection made? Would it
have to be javascript rather than PHP, or a function that is called?

The HTML table is within a DIV. Someone suggested using innerHTML.
But I cannot see how to re-display the entire DIV, with new values
from the combobox selection, without refreshing the page......this
seems impossible.

John.

Ugo
Guest
 
Posts: n/a
#2: Jun 27 '08

re: How to re-print values from combobox selection


[cut]
Quote:
But, once a selection is made, how do
I print the values to the page?
I'm not sure to understand your request, howover I write 2 code rows that
could be a start code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function()
{
document.forms[0].b.onclick = function()
{
var form = this.form;
form.t.value = '';
for( var i = 0, max = form.s.options.length; i < max; ++i )
if( form.s.options[i].selected )
form.t.value += form.s.options[i].text + '\n';
}
}
</script>
</head>

<body>
<form>
<select name="s" multiple="multiple" size="4">
<option>opt1</option>
<option>opt2</option>
<option>opt3</option>
<option>opt4</option>
<option>opt5</option>
<option>opt6</option>
</select>

<textarea name="t" rows="4" cols="10"></textarea>
<br />
<input type="button" name="b" value="write" />
</form>
</body>
</html>
Mtek
Guest
 
Posts: n/a
#3: Jun 27 '08

re: How to re-print values from combobox selection


On May 5, 11:10 am, Ugo <priv...@nospam.itwrote:
Quote:
[cut]
>
Quote:
But, once a selection is made, how do
I print the values to the page?
>
I'm not sure to understand your request, howover I write 2 code rows that
could be a start code:
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function()
{
document.forms[0].b.onclick = function()
{
var form = this.form;
form.t.value = '';
for( var i = 0, max = form.s.options.length; i < max; ++i )
if( form.s.options[i].selected )
form.t.value += form.s.options[i].text + '\n';
}}
>
</script>
</head>
>
<body>
<form>
<select name="s" multiple="multiple" size="4">
<option>opt1</option>
<option>opt2</option>
<option>opt3</option>
<option>opt4</option>
<option>opt5</option>
<option>opt6</option>
</select>
>
<textarea name="t" rows="4" cols="10"></textarea>
<br />
<input type="button" name="b" value="write" />
</form>
</body>
</html>
Well, we have a large DIV in the middle of the page, which gets it's
values from a PHP select to a MySQL Database,

<? PHP CODE ?>
<combo box>
<div id="innertable>
..
..
..
like 20 lines of code
</div>

Basically, when the value in the combo box changes, I want to refresh
the DIV with the corresponding values from the database. They do not
want to refresh the page.

So, I figure that somehow I can use some external page to query the
new data and refresh the DIV......

Never used AJAX, so I'm going to avoid that. Any ideas? Can
innerHTML help me here?

Thanks!

John.
Ugo
Guest
 
Posts: n/a
#4: Jun 27 '08

re: How to re-print values from combobox selection


Well, we have a large DIV in the middle of the page, which gets it's
Quote:
values from a PHP select to a MySQL Database,
>
<? PHP CODE ?>
<combo box>
<div id="innertable>
.
.
.
like 20 lines of code
</div>
>
Basically, when the value in the combo box changes, I want to refresh
the DIV with the corresponding values from the database. They do not
want to refresh the page.
ah ok,
I didn't understan before
Quote:
So, I figure that somehow I can use some external page to query the
new data and refresh the DIV......
>
Never used AJAX,
typically used for that
Quote:
so I'm going to avoid that. Any ideas? Can
innerHTML help me here?
One idea, for avoiding ajax, can be:
to preload every "div" correspondent with every option of the select and to
insert hidden, after on onchange of the select you put visible the
corresponden

this solution works bad if there are a lot of the options and/or the text
correspondent is too much...
Ugo
Guest
 
Posts: n/a
#5: Jun 27 '08

re: How to re-print values from combobox selection


[cut]
Quote:
So, the user selected the date ($pdate) from the combobox, it is used
to query the database, and the DIV is refreshed. I know this can be
done, but it is just a matter of finding the code or something
similar......
listen me, there are 3 way:
- or you preload all the contents, hide them and show at the event
- or you make a HTTP request to server (with "ajax")
- or you replace the DIV with a IFRAME

I don't understand other ways...
Closed Thread