Click to See Complete Forum and Search --> : Drop Down Menu & JS
ollmorris
12-28-2002, 07:28 AM
I have a drop down menu, however is there anyway I can tell if someone has selected an option. i.e with an onCLICK command for example. This is what I have tried:
<select name="font">
<option selected>Font...</option>
<option onSelect="AddText(this.form,7);">
Arial</option>
<option>Courier</option>
<option>Times New Roman</option>
<option>Verdana</option>
</select>
Thanks
gil davis
12-28-2002, 07:41 AM
An OPTION does not have an "onSelect" event. The most commonly used method is "onChange" in the SELECT tag.
ollmorris
12-28-2002, 11:08 AM
With the code I provided in my first post, how can I know what is selected in the drop down box?
Thanks
Put this one into your select tag to test:
onChange="alert(this.value)"
then you see what is selected.
ollmorris
12-28-2002, 11:51 AM
I have the code:
function AddText(form, Action){
var AddTxt="";
var txt="";
if(Action==7){
var font=this.value;
AddTxt=+font
}
form.Text1.value+=AddTxt;
}
<select name="font" onChange="AddText(this.form,7);">
<option selected>Choose a font...</option>
<option value="Arial" >Arial</option>
<option value="Courier">Courier</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Verdana">Verdana</option>
</select>
However, how can I get the variable FONT to show the value in the drop down menu?
Thanks
I don't see the whole function in your post, but to get the font value :
var font= document.yourFormName.font.value;
ollmorris
12-28-2002, 12:09 PM
I have edited my previous post to show the function.
Do you know of a script that allows me to control BOLD ITALIC etc like the one used in this forum whne you post a new thread/reply?
Thanks
Ok, this should be the solution for it:
<script language="JavaScript">
<!--
function AddText(form, Action){
var AddTxt="";
var txt="";
if(Action==7){
var font= form.font.value;
AddTxt=+font // maybe should replaced with += instead of =+
}
form.Text1.value+=AddTxt;
}
</script>
<select name="font" onChange="AddText(this.form,7);">
<option selected>Choose a font...</option>
<option value="Arial" >Arial</option>
<option value="Courier">Courier</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Verdana">Verdana</option>
</select>
There are a few ways to do this and other formats, but for that I must see the whole source.
ollmorris
12-28-2002, 12:38 PM
Thanks.
However, if I change the selected option in the DDM, how can I then get it to change the content in the textfield instead of adding data each time?
Try out something like that, it changes to bold, not adding:
if(Action==8)
{
var text = form.Text1.value;
range = document.selection.createRange()
selectioning = range.text;
selectioning = text.replace(selectioning,"<b>"+selectioning+"</b>");
form.Text1.value = selectioning;
}
your textfield has the name Text1 right, so put into the form for example a button like this to make it bold.
<button onclick="AddText(this.form,'8')">Make bold</button>