Hi All,
Here’s a challenge which I hope someone can help me with. I’ve got a piece of code on my form which, when the last option in a drop-down list is selected, an extra text field appears to enter an ‘Other..’ option.
What I’d also like to see is that when option 4 is selected (Name), two text fields appear so that the person completing the form can enter a first and last name.
Is this possible???
Thanks for any ideas!
<html><body>
<script type=”text/javascript” language=”JavaScript”>
function activate(field) {
field.disabled=false;
if(document.styleSheets)field.style.visibility = ‘visible’;
field.focus(); }
function last_choice(selection) {
return selection.selectedIndex==selection.length – 1; }
function process_choice(selection,textfield) {
if(last_choice(selection)) {
activate(textfield); }
else {
textfield.disabled = true;
if(document.styleSheets)textfield.style.visibility = ‘hidden’;
textfield.value = ”; }}
function valid(menu,txt) {
if(menu.selectedIndex == 0) {
alert(‘You must make a selection from the menu’);
return false;}
if(txt.value == ”) {
if(last_choice(menu)) {
alert(‘You need to type your choice into the text box’);
return false; }
else {
return true; }}
else {
if(!last_choice(menu)) {
alert(‘Incompatible selection’);
return false; }
else {
return true; }}}
function check_choice() {
if(!last_choice(document.forms[0].P_PUB_ID)) {
document.forms[0].p_choicetext.blur();
alert(‘Please check your menu selection first’);
document.forms[0].P_PUB_ID.focus(); }}
</script>
<form>
<table>
<td>
<select name=”P_PUB_ID” style=”width: 201px;” onchange=”process_choice(this,document.forms[0].p_choicetext)”>
<option selected>Select
<OPTION VALUE=”1″>First
<OPTION VALUE=”2″>Second
<OPTION VALUE=”3″>Third
<OPTION VALUE=”4″>Name
<OPTION VALUE=”99999″>Other, please specify:
</select>
<noscript>
</td>
<td valign=”top”><input type=”text” name=”p_choicetext” size=”22″ class=”textbox”>
</noscript><script type=”text/javascript” language=”JavaScript”><!–
disa = ‘ disabled’;
if(last_choice(document.forms[0].P_PUB_ID)) disa = ”;
document.write(‘</td><td valign=”top”><input type=”text” size=”30″ class=”textbox” name=”p_choicetext”‘+disa+
‘ onfocus=”check_choice()”>’);
if(disa && document.styleSheets)
document.forms[0].p_choicetext.style.visibility = ‘hidden’;
//–></script>
</td></table></form></body></html>