Page 1 of 1

javascript endless select boxes

Posted: Fri May 30, 2008 1:37 pm
by Bal
Hi again!

I'm writing a page that uses select boxes. One thing I would like to do when a selection is made in the select boxes is to generate another set of blank boxes, ad infinitum.

I understand this is a fairly simple thing, but am new to javascript (as in starting to learn it as I post this).


EDIT: Altered title and text to reflect purpose of post.

Re: PHP?

Posted: Fri May 30, 2008 3:16 pm
by Mini
I think that the thing you want is Javascript. Php is server based.
Well it seems like a simple thing you need, I'm sure you can find it easely on google ;).

Re: PHP?

Posted: Fri May 30, 2008 3:32 pm
by Luke
yea this is a client-side issue. this isn't something php would be capable of unless you actually submitted the page to the server.

Moving to client side...

EDIT: oh and you may want to change the title of your thread to something like "how do you generate a select box with javascript?" or something like that.

Re: javascript endless select boxes

Posted: Sun Jun 01, 2008 3:35 am
by kaszu
JS to create select box:

Code: Select all

var select = document.createElement('select');
select.name = 'new_select';
document.getElementsByTagName('body')[0].appendChild(select);
for(var i=0; i<10;i++) {
    var option = document.createElement('option');
    option.value = i;
    option.innerHTML = 'Value ' + i;
    select.appendChild(option);
}