Jump to content

PHP forms


c_pattle

Recommended Posts

Hey

 

I have a form on my website with a select box.  What I want to achieve is depending on what the user selects from this select box another select box will appear.  For example if the users selects either option 1, 3, or 6 from the first select menu a second one will appear.  Is this possible to do using PHP as I'm not sure how to do it. 

 

Thanks

Link to comment
Share on other sites

This could be done with html and javascript and no php as the behaviour is on the client side. For example:

<script language='javascript'>
function list1change()
{
	div1 = document.getElementById('div1');
	list1 = document.getElementById('list1');
	if (list1.selectedIndex==0 || list1.selectedIndex==2 || list1.selectedIndex==5)
		div1.style.display = 'block';
	else
		div1.style.display = 'none';
}
</script>
<form name=form1 method=get action=''>
<select name=list1 id=list1 onchange="list1change()">
	<option value="item1">item1</option>
	<option value="item2">item2</option>
	<option value="item3">item3</option>
	<option value="item4">item4</option>
	<option value="item5">item5</option>
	<option value="item6">item6</option>
</select>
<div name=div1 id=div1 style='display: block;'>
	<select name=list2>
		<option value="item1">item1</option>
		<option value="item2">item2</option>
		<option value="item3">item3</option>
	</select>	
</div>
</form>

 

As Karl points out, there is lots of information available on doing this, and general purpose libraries that handle the combination of html, javascript and php to simplify things.

Link to comment
Share on other sites

Thanks for your help.  I tried to adapt your script to include three divs for three different options but can't seem to get it to work. 

 

   function list1change()
   {
      div1 = document.getElementById('div1');
      order_property_details = document.getElementById('order_property_details');
      if (order_property_details.selectedIndex==0)
         div1.style.display = 'block';
      else if (order_property_details.selectedIndex==1)
         div2.style.display = 'block';
      else if (order_property_details.selectedIndex==2)
         div3.style.display = 'block';
      else
         div1.style.display = 'none';
         div2.style.display = 'none';
         div3.style.display = 'none';

   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.