There is another solution to display a hidden input when a user choose an option from the select tag?
I want to put the HTML code outside the JS code.
jQuery code:
$(function() {
var message = new Array(),
$paymentOption = $("#payement_option"),
$messageDisplay = $("#message_display");
message[1] = '<input type="text" name="email" size="30" />';
$paymentOption.change(function() {
var messageIndex = $(this).val();
$messageDisplay.empty();
if (messageIndex > 0)
$messageDisplay.append(message[messageIndex]);
});
});
HTML code like this:
<select name="option"><option value="0">yes</option><option value="1">no</option</select>
the output:
<div id="message_display"></div>
EDIT:
I want something like:
<div id="message_display">
<input type="text" name="email" size="30" />
</div>
I, as the others are bit confused, but from my understanding of your problem you have basically working code.
You need to set select id to payment_option and put the message display div on the page. otherwise it cannot find what it needs to append the value to.
change it to this:
HTML
JQUERY
and a live example: http://jsfiddle.net/mCqfq/
EDIT:
you mean like this? http://jsfiddle.net/dEwcK/
HTML:
CSS:
JQUERY: