need help with javascript and option fuction

PHP coding talk.

Moderator: Moderators

need help with javascript and option fuction

Postby wicho7 on Fri Jan 19, 2007 2:34 am

I am new in programming and i dont know much of this now because of that i came for help, i want to use the <option> fuction to change the color of the text of a simple guestbook i have in my page but i dont know what to modify in the javascript to make this to work, the original code i have is this

Code: Select all
<P align=left><form action="action.php" method="post" name= "post"> 
<br> 
<p><b>Name</b><br></p> 
<input type="text" name="name" /> 
<br> 
<p><b>email</b><br></p> 
<input type="text" name="email" /> 
<br> 
<p><b>Subject</b><br></p> 
<input type="text" name="subject" /> 
<br> 
<p><b>Comments</b><br></p>

<SCRIPT LANGUAGE='JavaScript'>

  <!--
  function Font(which) {
  document.post.message.value = document.post.message.value + which;
  }
  //-->
</SCRIPT>

<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
   <td><b>Color-></b><A HREF="javascript:Font('<FONT color=#FF0000>')"><IMG SRC="red.gif" BORDER=0 alt="red"></A>
<A HREF="javascript:Font('<FONT color=#0C00FF>')"><IMG SRC="blue.gif" BORDER=0 alt="blue"></A>
<A HREF="javascript:Font('<FONT color=#BE23BA>')"><IMG SRC="purple.gif" BORDER=0 alt="purple"></A>
<A HREF="javascript:Font('<FONT color=#00FF1E>')"><IMG SRC="green.gif" BORDER=0 alt="green"></A>
<A HREF="javascript:Font('<FONT color=#FFFF00>')"><IMG SRC="yellow.gif" BORDER=0 alt="yellow"></A>
<A HREF="javascript:Font('<FONT color=#FF6633>')"><IMG SRC="orange.gif" BORDER=0 alt="orange"></A>
<A HREF="javascript:Font('</FONT>')">Close tags</A></td>
</tr>
</table>


<textarea name="message" rows="10" cols="35" wrap="virtual" style="width:450px" ></textarea>
<br> 
<input type="submit" /> 
</form></P>


and i want to use the option and slect function in the part of the colors, something like this
Code: Select all
<select><option><A HREF="javascript:Font('<FONT color=#FF0000>')"><IMG SRC="red.gif" BORDER=0 alt="red"></A></option>
<option><A HREF="javascript:Font('<FONT color=#0C00FF>')"><IMG SRC="blue.gif" BORDER=0 alt="blue"></A></option>
<option><A HREF="javascript:Font('<FONT color=#BE23BA>')"><IMG SRC="purple.gif" BORDER=0 alt="purple"></A></option>
<option><A HREF="javascript:Font('<FONT color=#00FF1E>')"><IMG SRC="green.gif" BORDER=0 alt="green"></A></option>
<option><A HREF="javascript:Font('<FONT color=#FFFF00>')"><IMG SRC="yellow.gif" BORDER=0 alt="yellow"></A></option>
<option><A HREF="javascript:Font('<FONT color=#FF6633>')"><IMG SRC="orange.gif" BORDER=0 alt="orange"></A></option></select>


but i dont know how to make this work and i came for help, sorry if this is a question of newer but i am new in this and i donk now much of this and sorry for my english, my original language is spanish :roll:
wicho7
Registered User
Registered User
 
Posts: 5
Joined: Wed Jan 10, 2007 1:58 am

Postby PostBot on Fri Jan 19, 2007 6:39 pm

You can't put html code inside <option>

Use onchange() event of <select>, and set color as value to <option>. Like this:
Code: Select all
<select onchange="if(this.selectedIndex != -1) Font('<font color=#' + this.options[this.selectedIndex].value + '>'">
<option value="0C00FF">blue</option>
<option value="BE23BA">purple</option>
</select>
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby wicho7 on Sat Jan 20, 2007 2:58 am

I do what you say ciberalien but it dont work, the new code i made is this
Code: Select all
<P align=left><form action="action.php" method="post" name= "post"> 
<br> 
<p><b>name</b><br></p> 
<input type="text" name="name" /> 
<br> 
<p><b>email</b><br></p> 
<input type="text" name="email" /> 
<br> 
<p><b>subject</b><br></p> 
<input type="text" name="subject" /> 
<br> 
<p><b>Comments</b><br></p>
<SCRIPT LANGUAGE='JavaScript'>

  <!--
  function Font(which) {
  document.post.message.value = document.post.message.value + which;
  }
  //-->
</SCRIPT>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
   <td><b>Color-></b> 
<select onchange="if(this.selectedIndex != -1) Font('<font color=#' + this.options[this.selectedIndex].value + '>'"> 
<option value="000000">default</option> 
<option value="FF0000">red</option> 
<option value="0C00FF">blue</option> 
<option value="BE23BA">purple</option> 
<option value="00FF1E">green</option> 
<option value="FFFF00">yellow</option> 
<option value="FF6633">orange</option> 
  </select>
<A HREF="javascript:Font('</FONT>')">close tags</A></td>
</tr>
</table>

<textarea name="message" rows="10" cols="35" wrap="virtual" style="width:450px" ></textarea>
<br> 
<input type="submit" /> 
</form></P>


i want to know where si the error, sorry i am new in this :?
wicho7
Registered User
Registered User
 
Posts: 5
Joined: Wed Jan 10, 2007 1:58 am


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron