Jump to content

Display table contents from dropdown when link clicked

Recommended Posts

Hi, I am using the following code to display products and prices when dropdown selected. What I need to do though is for a certain table to be selected if the visitor to my site clicks on a particular link. For example if the visitor clicks a link for A2 Leaflets on my home page, I need the drop down to display A2 Leaflets products and prices when the new page loads. Can anyone suggest a way this can be done? I am guessing it only requires something simple to be added to the existing ajax code, I just dont know where to begin looking?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>  <title></title>  <script type="text/javascript">function showUser(){var user = document.getElementById("user").value;var type = document.getElementById("type").value;var finish = document.getElementById("finish").value;if (finish=="")  {  document.getElementById("txtHint").innerHTML="";  return;  }if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.onreadystatechange=function()  {  if (xmlhttp.readyState==4 && xmlhttp.status==200)		{		document.getElementById("txtHint").innerHTML=xmlhttp.responseText;		}  }xmlhttp.open("GET","getuser.php?q="+user+"&t="+type+"&f="+finish,true);xmlhttp.send();}</script><link rel="stylesheet" type="text/css" href="dropdown_form.css" media="screen" /></head><body><div id="prices_dropdown_form"><form id="dropdown_form"><select id="user"><option value="">Select Leaflet Type</option><option value="1">A2 Leaflets</option><option value="2">A3 Leaflets</option><option value="3">A4 Leaflets</option><option value="4">A5 Leaflets</option><option value="5">A6 Leaflets</option><option value="6">A7 Leaflets</option><option value="7">210x198 Leaflets</option><option value="8">210x396 Leaflets</option><option value="9">55x85 Leaflets</option><option value="10">1/3 A4 Leaflets</option><option value="11">6pp A4 Leaflets</option><option value="12">6pp A5 Leaflets</option></select><select id="type"><option value="">Select Paper Type</option><option value="1">120 Laser</option><option value="2">130 Gloss</option><option value="3">130 Silk</option><option value="4">170 Bond</option><option value="5">170 Gloss</option><option value="6">170 Silk</option><option value="7">250 Gloss</option><option value="8">250 Silk</option><option value="9">300 Bond</option><option value="10">350 Silk</option><option value="11">400 Silk</option><option value="12">400 Silk GLam1</option><option value="13">400 Silk GLam2</option><option value="14">400 Silk MLam2</option></select><select id="finish" onchange="showUser()"><option value="">Select Finish Type</option><option value="1">Flat</option><option value="2">Fold</option><option value="3">Creased & Flat</option><option value="4">Creased & Fold</option></select></form><br /><div id="txtHint"><b>Product Info & Prices</b></div></div></body></html>

Edited by johnty_johnson
Link to post
Share on other sites

The easiest way is to pass the values through the URL that you want to select, e.g. page.php?user=1. You can use Javascript to get the various things passed in the URL and select those options in the appropriate lists, although it would be a lot easier to do that with PHP if you're writing out the page with PHP.

Link to post
Share on other sites

Thanks for your reply. I was afraid it was going to get complicated. That's above my pay grade at the moment :( Is there anyway to just have the first value displaying when the page is loaded. For example, customer clicks leaflets and is brought to a page where A2 Leaflets is the default table showing? I tried to do this by adding selected to <option> and while it does choose A2 as the selected option it doesn't display the table. I know this is due to how the script displays the information, can anyone offer a solution? This has been bugging me for days!

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...