/    Sign up×
Community /Pin to ProfileBookmark

drop down box to change text color without button

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

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJun 21.2004 — Hi!

Example:[code=php]<!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>[/code]
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
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — Hi

when I type on text field it types with colour but it shows output in black

?
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — maybe its because on click it changes dropdown to black and also enter as black
Copy linkTweet thisAlerts:
@PittimannJun 21.2004 — 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.[/QUOTE]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
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — because on click I'm refeshing my page
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — I'm using php
Copy linkTweet thisAlerts:
@PittimannJun 21.2004 — Hi!

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

Cheers - Pit
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — 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
Copy linkTweet thisAlerts:
@ysheraziauthorJun 21.2004 — 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
Copy linkTweet thisAlerts:
@ysheraziauthorJun 23.2004 — 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
×

Success!

Help @ysherazi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...