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

Link to comment
Share on other sites

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();
}

Link to comment
Share on other sites

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

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.