Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Thanked 0 Times in 0 Posts

    Need Help with Drop down menu w/Option box.

    I have a form I'm trying to use java script to work with my drop down. I'm told that I don’t have any functionality to change the name of the fields. How do I add some JavaScript to change the name of the select box from ssl_amount to something else and the name of the text box that appears to ssl_amount.

    <script type="text/javascript">
    function toggleField(val) {
    var o = document.getElementById('ssl_amount');
    (parseInt(val) == 000)? o.style.display = 'block' : o.style.display = 'none';
    <select name="ssl_amount" id="ssl_amount" onChange="toggleField(this.value);">
    <option value="0" selected>Select Amount</option>
    <option value="000">Other</option>
    <input type="text" name="other" id="ssl_amount" style="display: none;">

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Thanked 508 Times in 502 Posts

    Question Unsure of concept ...

    I'm not sure why you are trying to set a text field with the select option value but only display it if it is '000'
    But if that is your desire, then:
    <title>SBox change</title>
    <script type="text/javascript">
    function toggleField(info) {
      var o = document.getElementById('ssl_amount');
      o.value = parseInt(info).toFixed(2);
      o.style.display = (info == '000') ? 'block' : 'none';
    <select name="ssl_amount" onchange="toggleField(this.value)">
    <option value="0" selected>Select Amount</option>
    <option value="2400">2400.00</option>
    <option value="1000">1000.00</option>
    <option value="500">500.00</option>
    <option value="250">250.00</option>
    <option value="100">100.00</option>
    <option value="50">50.00</option>
    <option value="1">1.00</option>
    <option value="000">Other</option>
    <input type="text" name="other" id="ssl_amount" value="" style="display:none">
    If you are trying to display the text only if the selection is 'other' and allow user to enter a number,
    then you will need to modify script above a bit.

    Also note that you must make the id value unique. You cannot have 2 elements named 'ssl_amount'

    It would also be helpful to enclose you script between [ code] and [ /code] tags (without the spaces)
    to make it easier for forum members to read and/or copy.


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts