TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Form menu help :( (http://www.talkphp.com/general/5389-form-menu-help.html)

Tim Dobson 04-03-2010 02:56 PM

Form menu help :(
 
Ok straight to business we wont mention the queen!

I have a list menu:

PHP Code:

<select name="mydropdown">
  <
option value="List">View as list</option>
  <
option value="Show">View as slide-show</option>
</
select

meh thats it really. What i need it to do is change what is on the page when its changed. So as an example could someone show me how i would just go about changing a bit of text depending on which option it is on please? i have looked at loads of examples and all of them increased my confusion state lol :D thanks

adamdecaf 04-03-2010 04:31 PM

There is a simple way to do this.

html4strict Code:
<select name="mydropdown" onchange="change_content(this.options[this.selectedIndex].value);">
  <option value="List">View as list</option>
  <option value="Show">View as slide-show</option>
</select>

javascript Code:
function change_content(id, element) {
  // alert(id);

  // Now that we have the id we can grab documents with an XHR or
  // just change the content here.
 
  // For example if _element_ is an ID from an HTML Element
  var elm = document.getElementById(element);

      elm.innerHTML = id;

  // Or...
  // Remember, IE doesn't support this function.
  var xhr = new XMLHttpRequest();
      xhr.open('GET', 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' + encodeURIComponent(id), false);
      xhr.send(null);

  // Now just parse the json
  // You should use this script.
  // [url]http://json.org/json2.js[/url]
  var response = JSON.parse(xhr.responseText);

  // And then fill the element
  var n = 0, count = response.length;
  while (n < count) {
     elm.innerHTML += ....
     n++;
  }

}

Tim Dobson 04-03-2010 06:22 PM

ok so i dont know if im 1 step closer or not... its all jibberish to me lol.

what if i just want it to pull out the include ?

on View as list option i need it to do:
PHP Code:

<?php include ("includes/list.php");?>

and on View as slide-show option i need it to do
PHP Code:

<?php include ("includes/slideshow.php");?>


adamdecaf 04-03-2010 07:14 PM

Where did the includes come from? The code that I posted above needs to be loaded on the same page [after it is completed] (how ever it's done doesn't matter).


All times are GMT. The time now is 07:15 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0