Forum Moderators: open

Message Too Old, No Replies

javascript conditional form fields help

how to make conditional fields appear

         

MizDove

2:13 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



I can see that the example I posted at first can not work. So I'm at a total loss how to do this.

I am trying to make a form field appear if a certain value is chosen from a dropdown.

Can this be done in javascript?

[edited by: MizDove at 2:45 pm (utc) on July 6, 2007]

MizDove

3:52 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



I figured this out. Right or wrong, it works. Thanks anyway, everyone.

<script type="text/javascript">
function showfield(x)
{
var y=document.getElementById(x).value

if (y=="Group")
{
document.getElementById("displayme").innerHTML = 'Names of other attendees in firm: <input type="text" name="namesattending" size=30>';

}
else
{
document.write('')
}

}
</script>
</head><body>
<form action="test5.asp" method="post">
type something here:
<input type="text" name="tttt" size=20>
<br><br>
Select tuition:
<input type="radio" name="Tuition" value="Group" id="fname"
onchange="showfield(this.id)">Group<br>
<input type="radio" name="Tuition" value="Standard">Standard<br>
<input type="radio" name="Tuition" value="EarlyBird">Early Bird<br>
<br>
<div id="displayme"></div>
<input type="submit" value="Register">

rocknbil

6:11 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ony one problem, as revealed in this thread [webmasterworld.com] - if Javascript is disabled it won't work. You are better off actually including the conditional field in the HTML and hiding it in window.onload().