Click to See Complete Forum and Search --> : drop down box to change text color without button


ysherazi
06-21-2004, 12:57 AM
hi everybody

I need help in creating a drop down box.so that user can select colour for the text.

I need this for my chattingsoftware

I'll really approciate help

;)
safe

Pittimann
06-21-2004, 01:28 AM
Hi!

Example:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function selColor(sel,selIndex,tArea){
tArea.style.color=sel.options[selIndex].value;
}
//-->
</script>
</head>
<body>
<form>
<select onchange="selColor(this,this.selectedIndex,this.form.text)">
<option value="black">black</option>
<option value="green">green</option>
<option value="yellow">yellow</option>
<option value="red">red</option>
<option value="gray">gray</option>
<option value="blue">blue</option>
</select><br>
<textarea name="text" cols=50 rows=12></textarea><br>
</form>
</body>
</html>You will have to use the value of the selected option in your server side script to format the text in your output frame as well.

Cheers - Pit

ysherazi
06-21-2004, 02:10 AM
Hi
when I type on text field it types with colour but it shows output in black

:(

ysherazi
06-21-2004, 02:15 AM
maybe its because on click it changes dropdown to black and also enter as black

Pittimann
06-21-2004, 02:17 AM
Hi!

That's what I said:You will have to use the value of the selected option in your server side script to format the text in your output frame as well.I don't know what server side language you are using and I don't know, what you output. If you use spans or divs for the output, you will need to have your server side script add css properties for the container with the text to be displayed.

Cheers - Pit

ysherazi
06-21-2004, 02:20 AM
because on click I'm refeshing my page

ysherazi
06-21-2004, 02:22 AM
I'm using php

Pittimann
06-21-2004, 02:36 AM
Hi!

Assuming, your form's method is "get" and you name the select tag "textColor", you could use something like that:<?php
$color=$_GET['textColor'];
$text=$_GET['text'];
echo '<div style="color:'.$color.'">'.$text.'</div>';
?>I put a simple example online, using the above snippet: http://www.pit-r.de/scripts/ysherazi/dropdownForColorInTextarea.htm

Cheers - Pit

ysherazi
06-21-2004, 03:11 AM
man it's giving me arrors I'm doing something wrong

can u give me ur email adress

is it possible I send u the file and u look at it I hope I'm not getting on ur nerves

ysherazi
06-21-2004, 03:49 AM
input file...

if(isset($_POST['textColor']))
{
$col=$_POST['textColor'];
echo $col;
}
else
{
$col="black";
}
if(isset($_GET['col']))
{
$col=$_GET['col'];
}

echo"
<head>
<script language='JavaScript' type='text/JavaScript'>
function refreshpage()
{
parent.mainFrame.location.href='messages.php?val=$val';
setTimeout('refreshpage()',5000);
}
function refreshpage1()
{
parent.mainFrame.location.href='messages.php?val=$val&col=$col';
document.forms[0].txt.focus();
}
function selColor(sel,selIndex,tArea){
tArea.style.color=sel.options[selIndex].value;
}

document.write('<b>' + (new Date).toLocaleString() + '</b>');

</script>
</head>";

echo "<body onload ='refreshpage();refreshpage1()'>";
if(isset($_SESSION['user_name']))
{

if(isset($_POST['txt']))
{
$fileOpen=@fopen($val.".txt", "a");
$text="<font color=#ff0000><b>".$_SESSION['user_name'].">> </b></font>".$_POST['txt']."<br>";
@fwrite($fileOpen,$text);
@fclose($fileOpen);
}

$query="update users set view=1 where user_id='$id'";
$r3=mysql_query($query) or die(mysql_error());
}
else
{
if(isset($_POST['txt']))
{
$fileOpen=@fopen($_SESSION['nickname'].".txt", "a");
$text="<font color=#ff0000><b>".$_SESSION['nickname'].">> </b></font>".$_POST['txt']."<br>";
@fwrite($fileOpen,$text);
@fclose($fileOpen);
}

}
echo "<style type=text/css>BODY{font-family:Verdana, Arial, Helvetica, sans-serif}</style>
<form name=form1 method=post action='input.php?col=$col'>
<input name=txt type=text size=50 id=txt >
<select name=textColor onchange=selColor(this,this.selectedIndex,this.form.txt)>
<option value=black>black</option>
<option value=green>green</option>
<option value=yellow>yellow</option>
<option value=red>red</option>
<option value=gray>gray</option>
<option value=blue>blue</option>
</select><br>

<input type=submit name=Submit value= Chat! onclick = refreshpage1()>
<a href=logoff.php target=_top> Log Off </a></form>";


outputfile................

if(isset($_GET['col']))
{
$col=$_GET['col'];
}
}
if(isset($_SESSION['nickname']))
{
$file=$_SESSION['nickname'];
$fileName=$file.".txt";
$fileOpen=@fopen($fileName,"rb");
$fileRead=fread($fileOpen,1024000);
echo "<font color=$col>".$fileRead."</font>";
@fclose($fileOpen);
}

I hope u can undestand

regards

ysherazi
06-23-2004, 02:54 AM
hi
I have a problem.

I'm using onclick for refreshing my input page but am also using dropdown menu to change the color of the text but when I write text and chooose colour it changes but once I submit text it changes to black againbecause it is default.

can you guide me what should I do so that when I submit value it should stick with the color I choose.

mesg page is used to show output. I'm passing the colour value to msg page but because of refresh it turn back to black