PDA

View Full Version : onclick form



EKsparky
02-08-2008, 12:21 PM
Hi
I am writing my own mini cms mostly in php
I writtern my own news with bbcode type links
I want to ba able to add text to my form when bbcode images are clicked
I.E click B and [b][\b] is added to form (just like this text box i am posting in now)
now i found a snippet of code that does this but my problem is using it for all my images B I U img etc etc i guess i need to add id some how

<html>

<head>

<title></title>

<script type="text/javascript" language="javascript"><!--

function ChgText()
{
var MyElement = document.getElementById("MyTextBox");
MyElement.value = "[b][\b]!";

return true;
}

//--></script>


</head>

<body>

<br><br>
<center>
<img src="my_image.gif" alt="Click Me!" onClick="ChgText()" />

<br><br><br>

<input type="text" size="35" id="MyTextBox" />

</center>

</body>
</html>
Thanks

Nile
02-08-2008, 12:36 PM
Try this:

<html>

<head>

<title></title>

<script type="text/javascript" language="javascript"><!--

function ChgText(s)
{
var MyElement = document.getElementById("MyTextBox");
MyElement.value = "["+s+"][\"+s+"]";

return true;
}

//--></script>


</head>

<body>

<br><br>
<center>
<img src="my_image.gif" alt="Click Me!" onClick="ChgText('b')" /><!-- This makes the Bold click --!>

<img src="my_image.gif" alt="Click Me!" onClick="ChgText('i')" /><!-- This makes the Italics click --!>

<img src="my_image.gif" alt="Click Me!" onClick="ChgText('u')" /><!-- This makes the Underline click --!>
<br><br><br>

<input type="text" size="35" id="MyTextBox" />

</center>

</body>
</html>
Read the comments in the HTML!

EKsparky
02-08-2008, 01:13 PM
Thanks Nile for quick reply i can see how that would work
first i just edited my code no luck
so i pasted your code into notepad2 & dreamweaver the highlighting is wrong so i guess tag missing somewhere but i can t seem to see where :o

obviously i removed your comments