Jump to content

Select onchange should refresh page and pass variable


tinmanjim

Recommended Posts

This is probably laughably simple, but after a couple of hours searching, I figured it might be simplest to rely on the kindness of strangers...

 

I'm using a simple php news application called phpns. It uses categories numbered 1 - n, and before the call to display the news function one of the calling parameters is the category number(s). I have a select list with an onchange statement, and would like to refresh the page, passing the selected index for use in the new call to shownews.

 

As I said, I know it's simple, but would greatly appreciate any assistance.

 

Thanks

How does the PHP script get the number normally? Does it use a $_GET or $_POST?

 

A simple solution would to make the form that the select is contained in submit on change, for example if you have the forms id of "myForm" and the select was an id of "category_id"

 

document.getElementById('category_id').onchange() {
     document.getElementById('myForm').submit();
}

My code looks like this:

 

<?php
   if (!isset($_GET['catID']))
      $catNum = 0;
   else
      $catNum = $_GET['catID'];
               
   $phpns['category'] = $catNum;
   include("news/shownews.php");

?>
<form name="catSelect" action="self" method="get" >
   <select name="catID" id="catID" onchange="catSelect.submit()">
      <option value="0">Title</option>
      <option value="1">Category 1</option>
      <option value="2">Category 2</option>
      <option value="3">Category 3</option>
    </select>
</form>

I'm using a news package called phpns that uses the 'category' call to pass the desired category to the shownews page.

This is all on the news page, so the page should reload when an option is selected, passing the selected value to $catNum, then calling phpns.

 

I'm not sure what's wrong...

Archived

This topic is now archived and is closed to further replies.

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