Question about accessing <SELECT>

R

rebeccatre

Below code works to insert a line into my select box. I would also
like to set the CSS class as well, but I have not been able to modify
this to work there. Can someone please help me? Thank you, I would
appreciate it so much. Rebecca


<script>
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
</script>


<FORM name="drop_list" action="newpage.htm" method="POST" >
<SELECT NAME="Month_list">
<Option value="">Month list</option>
</SELECT>
</form>


<!-- BELOW, WOULD LIKE TO INSERT A CSS VALUE ALSO
---------------------->
<script>
addOption(document.drop_list.Month_list,"January", "January");
</script>
 
D

David Mark

Below code works to insert a line into my select box. I would also
like to set the CSS class as well, but I have not been able to modify
this to work there. Can someone please help me? Thank you, I would
appreciate it so much. Rebecca

<script>
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);}

</script>

<FORM name="drop_list" action="newpage.htm" method="POST" >
<SELECT NAME="Month_list">
<Option value="">Month list</option>
</SELECT>
</form>

<!-- BELOW, WOULD LIKE TO INSERT A CSS VALUE ALSO
---------------------->
<script>
addOption(document.drop_list.Month_list,"January", "January");
</script>

<script type="text/javascript">
function addOption(selectbox,text,value,className )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
optn.className = className;
selectbox.options.add(optn);


}


</script>

<FORM name="drop_list" action="newpage.htm" method="POST" >
<SELECT NAME="Month_list">
<Option value="">Month list</option>
</SELECT>
</form>


<!-- BELOW, WOULD LIKE TO INSERT A CSS VALUE ALSO
---------------------->
<script type="text/javascript">
addOption(document.drop_list.Month_list,"January", "January",
'myclass');
</script>
 
R

rebeccatre

<!-- BELOW, WOULD LIKE TO INSERT A CSS VALUE ALSO
---------------------->
<script type="text/javascript">
addOption(document.drop_list.Month_list,"January", "January",
'myclass');
</script>

Da-da! Awesome -- thank you David!! Have a wonderful rest of week!
BEST-Rebecca
 
R

rebeccatre

May I ask you one more question since you seem to be as close to a
Javascript expert as it gets,.... how would one reverse this, to
subtract a line out? :)
 
R

rebeccatre

BTW David, I do see one way to do this, using something like this

document.drop_list.Month_list.options[1]=null

However, is there a more direct way to 'id' a line, remove it, rather
than using its position in the list?* I have a dynamic list with a
couple of options I want to work with.... but don't want to put them
at the top of the list :) I hope you understand what I am getting
at* :) THANK YOU FOR INSIGHT!!!*
 

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,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top