1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

On selection do something

Discussion in 'JavaScript' started by PHPGator, Oct 4, 2007.

  1. #1
    Hello,

    I am pretty bad at javascript. Essentially I have a form with a pulldown menu. In the pulldown menu there is a "Other" option. WHat I want to happen when the user selects "other" is for another field to appear next to it and allow them to type in something.
    SEMrush
    Can someone show me an example? I couldn't find one online but I know it is possible. :)
     
    PHPGator, Oct 4, 2007 IP
    SEMrush
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    onchange="if( this.value = 'other' ) { do_shit(); }"
     
    Synchronium, Oct 4, 2007 IP
  3. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How is the text box going to be displayed is it just hidden or would you like it to be created in js.
     
    joesgraphics, Oct 4, 2007 IP
  4. PHPGator

    PHPGator Moderator Staff

    Messages:
    4,437
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    260
    #4
    I was using just standard HTML to create the form.

    <select name="color">
    <option value="Other">Other</option>
    </select>

    That is how I currently have it setup (minus some css stuff).

    I Just want a <input type="text" name="other"> to appear if Other is selected in the pull down menu.
     
    PHPGator, Oct 4, 2007 IP
  5. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ill pm you.
     
    joesgraphics, Oct 4, 2007 IP
  6. james_r

    james_r Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <script>
    function ShowHideTextBox() {
    if (document.getElementByName("color").value == "Other")
    {
    document.getElementById("textboxDiv").style.display = "block";
    }
    else
    {
    document.getElementById("textboxDiv").style.display = "none";
    }
    }
    </script>


    <select name="color" onclick="ShowHideTextBox()">
    <option value="Other">Other</option>
    </select>

    <div style="display:none;" id="textboxDiv">
    <input name="this_is_the_text_box" />
    </div>
     
    james_r, Oct 5, 2007 IP