...

View Full Version : help with onchange



Sayian
01-28-2006, 08:45 PM
Hi, im trying to load the value of an option like this



<select class="textbox" onchange="javascript:createBBtag('font here','','message')">
<option value="-">Font Name</option>
<option value="Arial">Arial</option>
<option value="Book Antiqua">Book Antiqua</option>
<option value="Comic Sans Ms">Comic Sans Ms</option>
<option value="Courier New">Courier New</option>
<option value="Georgia">Georgia</option>
<option value="Impact">Impact</option>
<option value="Lucida Sans">Lucida Sans</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Trebuchet MS">Trebuchet MS</option>
<option value="Tahoma">Tahoma</option>
<option value="Verdana">Verdana</option>
</select>


When i select the font, id like it to load into the font= tag in the onchange handler. I tried this.form.value but im still new to Javascript, and obviously didnt do it right, please help.

Mr J
01-28-2006, 09:03 PM
Your onchange should be something like this


onchange="javascript:createBBtag(this.options[selectedIndex].value,'','message')"

Sayian
01-28-2006, 09:27 PM
Thanks for the help, although im having trouble getting this to work right still.

onchange="javascript:createBBtag('.value]','','message')"

i need it to read [.font="font"]

its printing to the textbox .value]

Sayian
01-28-2006, 11:25 PM
is their no way to do this?

Sayian
01-29-2006, 02:01 AM
Ok, so can someone tell me where i could go to get an answer for this question since no one here seems to be able to answer it?

arnyinc
01-29-2006, 02:52 AM
Ok, so can someone tell me where i could go to get an answer for this question since no one here seems to be able to answer it?

I can tell you exactly where to go.

Unless you're paying me, or at least being polite and explaining your problem well, what can you really expect?

Anyways, you didn't show your existing form, javscript function, or even explain what you want to happen when the onchange triggers. Here's some code I wrote up that may or may not do what you're looking for. The important part is that you want: [font='+this.options[selectedIndex].value+']

<html>
<head>
<script language="javascript">
function createBBtag(tagtype, whichfont){
if (tagtype=='font')
document.myform.messagebox.value += '<font='+whichfont+'></font>'; //forum doesn't allow square brackets so I made them arrow brackets
}
</script>
</head>
<body>

<form name="myform">

<select class="textbox" onchange="createBBtag('font', this.options[selectedIndex].value)">
<option value="-">Font Name</option>
<option value="Arial">Arial</option>
<option value="Book Antiqua">Book Antiqua</option>
<option value="Comic Sans Ms">Comic Sans Ms</option>
<option value="Courier New">Courier New</option>
<option value="Georgia">Georgia</option>
<option value="Impact">Impact</option>
<option value="Lucida Sans">Lucida Sans</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Trebuchet MS">Trebuchet MS</option>
<option value="Tahoma">Tahoma</option>
<option value="Verdana">Verdana</option>
</select>

<br>

<textarea name="messagebox"></textarea>

</form>
</body>
</html>

Sayian
01-29-2006, 03:11 AM
Thank you, i am grateful. 1 question, would this code work in both IE and Firefox?

arnyinc
01-29-2006, 03:17 AM
Yep, it should. I tested it out in FireFox and IE6. Hope it works out for you.

Sayian
01-29-2006, 03:23 AM
Thanks, i actually have it working right now. I really appriciate it, theirs only 1 problem im facing though, for some reason i cant nest tags.

Im not really sure what could be causing this, do i need more code to be able to nest tags?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum