By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

How to re-print values from combobox selection

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ugo
[cut]
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>
Jun 27 '08 #2

P: n/a
On May 5, 11:10 am, Ugo <priv...@nospam.itwrote:
[cut]
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.
Jun 27 '08 #3

P: n/a
Ugo
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.
ah ok,
I didn't understan before
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
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...
Jun 27 '08 #4

P: n/a
Ugo
[cut]
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...
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.