Textfield visibility

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KSL
Forum Newbie
Posts: 5
Joined: Thu May 01, 2008 6:39 am

Textfield visibility

Post by KSL »

Hi i am new to PHP so this may (hopefully) just be a simple problem.

I am creating a contact form on my website using some freeware code i have found. The page works perfectly but i wanted to do a little tweeking.

In my form i have the question with a list/menu box "where did you find us", one of the selections is google. When this is selected by the user i want a previously hidden text field to appear asking which search term they used to find our site.

Can anybody help out with this code?

Cheers

KSL
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Textfield visibility

Post by aceconcepts »

You could do this with PHP by it would mean the user would have to click a submit button - not very good.

Your best bet would be to use Javascript.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Textfield visibility

Post by pickle »

Ya, you should use Javascript for this.

Something like (not tested):

Code: Select all

 
function showField()
{
  if(document.getElementById('pulldown').value == 'google');
    document.getElementById('myHiddenField').style.display = 'inline';
  else
    document.getElementById('myHiddenField').style.display = 'none';
}
.....
 
<select id = "pulldown" onchange = "showField();" >
...
</select>
<input type = "text" id = "myHiddenField" style = "display:none;" />
 
 
If the javascript solution is what you're looking for, I can move this thread to the Client-Side forum if you want.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
KSL
Forum Newbie
Posts: 5
Joined: Thu May 01, 2008 6:39 am

Re: Textfield visibility

Post by KSL »

Thank you all sorted now.
Post Reply