Grow your CSS skills. Land your dream job.

Conditional form events

  • # August 26, 2008 at 6:59 am

    Hello, I was wondering if anyone has any good examples of a form, that I assume would use AJAX or some type of Javascript framework, that can trigger an event based on another event. That probably doesn’t make much sense, but what I’m looking to do is if a user selects ‘other’ from a dropdown list, then I would like a text box to appear, giving the user the ability to enter information regarding why they selected ‘other’. I could certainly do this once the form is submitted, but I would like it to appear automatically without the user having to click the submit button.

    Any ideas???

    Thanks for your time!

    box
    # August 26, 2008 at 7:48 am

    Yes, this would be ajax – its a fairly common use of ajax, and although this certainly isn’t my area of expertise (something I definitely need to work on the way the web’s going) I’d be confident of finding a good example with a google search.

    # August 26, 2008 at 8:13 am

    Thanks Box, I thought the same thing, but I haven’t been able to find a solid example of what I am looking for. I am able to find all sorts of validation and I use it quite a bit, but I haven’t had much luck in looking for the conditional event trigger.

    Thanks.

    box
    # August 26, 2008 at 8:26 am

    Having thought about it – this could be achieved with just javascript. Ajax is used when you need to make a real-time request to the server, but if you’re just wanting an area to smoothly appear when an option is selected, then JavaScript would do it.
    You would construct your form in the usual way – including the ‘other’ text box so that the form is fully functional when javascript isn’t present. Then you could use a show/hide javascript function to allow the ‘other’ textarea to appear when ‘other’ is clicked. Again, javascript isn’t my area really, but you might have more luck finding a show/hide event tutorial for javascript than ajax? I hope so :)

    Chris might like to chip in here with his jQuery expertise ;)

    # August 26, 2008 at 6:07 pm

    check the basic jquery video cast chris did. You can just use it to show / hide the relevant fields as box said.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".