Web Analytics Made Easy -
StatCounter Resetting Selectbox - CodingForum

Announcement

Collapse
No announcement yet.

Resetting Selectbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resetting Selectbox

    Hello,

    I've come across a problem while making a posting system on my website. I would like to have my select box so that the user can add some coloured text into the post by choosing an option from the drop down box, causing text to be added to my textarea "combox" and then have the combobox reset to the default value (the Font Color selection) but after trying various code from googleing, I still cannot seem to manage this

    Sample code from the select box in my form "postcom":
    Code:
    echo "<SELECT NAME='fontcol'>";
    echo "<OPTION VALUE='none' DEFAULT>Font Color </OPTION>";  
    echo "<OPTION style='color:red' onClick=addtext(\"[font color=red]YOURTEXT[/font]\"); VALUE='red'>Red</OPTION>";
    echo "<OPTION style='color:blue' onClick=addtext(\"[font color=blue]YOURTEXT[/font]\"); VALUE='blue'>Blue</OPTION>";
    etc..
    and the function is:
    Code:
    <script language="javascript" type="text/javascript">
    function addtext(newtext) {
      document.postcom.combox.value += newtext;
      >> i would like at this point to reset the combobox to the default value <<
      document.postcom.combox.focus();
    }
    </script>
    And, I have just now noticed that the addtext() function is only being triggered in Firefox and Opera, but not Internet Explorer. Help would be greatly appreciated

    Regards,

    Signify

  • #2
    You'll have better results if you use the onchange event and you put it on the <select> tag, passing "this.value" to the function.

    Comment


    • #3
      Fumigator, thank you for the suggestion. I tried that approach and it now works fine on all browsers.

      My last issue is switching the chosen selection in the select box. Either by resetting it or by making it select the Font Color option specifically. Can this be done with .focus()? I'm guessing there's another way, but cannot seem to find information on it.

      Comment


      • #4
        Depends how you want to approach it. The quickest and dirtiest method would be...assuming you know where $color is coming from....

        <select.....>
        <option ..... value="red"<?php echo $color == 'red' ? ' selected="selected"' : ''; ?>>Red</option>
        .......
        </select>
        Active PHP/MySQL application developer available for immediate work.
        syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

        Comment

        Working...
        X