Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unhide form field if value from another field = other 1

Status
Not open for further replies.

humbleprogrammer

Programmer
Oct 30, 2002
315
0
0
US
Hi,

I have a form with a couple of dropdown boxes. I want to show another form field (other description) only if other is chosen from the drop down box. I have accomplished this using VBScript, a querystring (type=text) and the onchange event, but am only able to get it to work if I have the form submit to itself. Is there a way I can open up another form field using JavaScript without having to submit the form? I suck at JavaScript so any help is greatly appreciated.

Thanks!
 
hello humble programmer

I have a code , a mixture of Javascript and ASP

There are 2 related dropboxes.
If the user selects a value in one, automatically the second dropbox is enabled and filled with values.
If the user selects a different item in the first dropbox, the second dropboxes changes its values
This is done without submitting the form

Is that what you are looking for?
 
I prefer to use something like this, because it gives you the ability to reset the "value" of the "hidden" field depending on the value of the first field.

<script language=&quot;JavaScript&quot;>
function checkfield()
{
if (formname.fieldname1.value == &quot;Yes&quot;)
{
paraOtherField.innerHTML = '<font face=&quot;Verdana&quot; size=&quot;2&quot;><b><i>Fill in data:&nbsp;</i></b></font><input type=&quot;text&quot; name=&quot;fieldname2&quot; size=&quot;100&quot; value=&quot;test&quot; style=&quot;font-family: Arial; font-size: 8pt; font-weight: bold&quot;>';
}
else
{
paraOtherField.innerHTML = '<input type=&quot;hidden&quot; name=&quot;fieldname2&quot; size=&quot;12&quot; value=&quot; &quot;>';
}
}
</script>

</head>

<body>

<form method=&quot;POST&quot; action=&quot;gosomewhere.asp&quot; name=&quot;formname&quot; ID=&quot;formname&quot;>
<input type=&quot;text&quot; name=&quot;fieldname1&quot; size=&quot;100&quot; style=&quot;font-family: Arial; font-size: 8pt; font-weight: bold&quot; onChange=&quot;checkfield()&quot;>
<div id=&quot;paraOtherField&quot;></div>

</form>

<script language=&quot;JavaScript&quot;>
checkfield();
</script>

</body>

(You can run the function as an &quot;on-load&quot; to populate the div's, or manually enter the initial content of the div's, or run the function at the end of the body to load the initial value of the div's.)

hope this helps.
 
Thank you VERY much crowell! This is exactly what I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top