SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: using onchange

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool using onchange

    I have two drop downs used to reload the page displaying selected information.

    How do I get the OnChange function to pass year and user from the drop
    down. I also need to pass data in the array $month.

    PHP Code:
    <html>
    <head>
    <body>
    <script language="JavaScript" type="text/JavaScript">
    <!--

    function OnChange(dropdown)
    {
      //reload page after drop down selection
      window.location.href="http://localhost/month_view.php?u_user_id=" +
      dropdown.options[dropdown.selectedIndex].value    "&year="+   "&month="+ ;
    }
    --->


     <table>
       <tr><td>
         <!--year drop down-->
         <select name ="year" onChange ="javascript:OnChange(this)"
          <option value="">Select</option>
          <option value="2007">2007</option>
          <option value="2008">2008</option>
         </select>

        
          
         <select name = "user_id" onChange ="javascript:OnChange(this)"
          <option value="">Select</option>
          <option value="1">Frank</option>
          <option value="2">Mark</option>
         </select>
         
    </td>    
    </tr>
    <tr>
    <td>
     <?php
         
    //display information based on selected year, month and user
         
    display_info($year$month$user);
     
    ?>
        
    </td>
    </tr>
    </table>
    </body>
    </head>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You code contains a few errors. The corrected version:

    Code:
    <html>
    <head>
    <script language="javascript" type="text/javascript">
    function OnChange()
    {
      var userId = document.getElementById('user_id').value;
      var year = document.getElementById('year').value;
      var month = document.getElementById('month').value;
      if (userId == "" || year == "" || month == "")
        alert('Please correct your input.');
      else {
        window.location.href="http://localhost/month_view.php?user_id="
          + userId + "&year=" + year + "&month=" + month;
      }
    }
    </script>
    </head>
    <body>
     <table>
       <tr><td>
         <!--year drop down-->
         <select id="year" onchange="submitData();"
          <option value="">Select</option>
          <option value="2007">2007</option>
          <option value="2008">2008</option>
         </select>
         <select id="month" onchange="submitData();"
          <option value="">Select</option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
         </select>
         <select id="user_id" onchange="submitData();"
          <option value="">Select</option>
          <option value="1">Frank</option>
          <option value="2">Mark</option>
         </select>
    </td>    
    </tr>
    <tr>
    <td>
     <?php
         //display information based on selected year, month and user
         display_info($_GET['year'], $_GET['month'], $_GET['user_id']);
     ?>
    </td>
    </tr>
    </table>
    </body>
    </html>
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the response and great suggestion.
    I could not a single function to work.
    I could get 2 seperate functions working and it does the job.

    I am curious why your suggestion won;t work as one function but will wor as two?

    solution

    PHP Code:
    <html>
    <head>
    <script language="javascript" type="text/javascript">

    function YearChange()
    {
       var year = document.getElementById('year').value;
       window.location.href="http://localhost/month_view.php?year=" + year;
    }

    function ProChange()
    {
       var providerId = document.getElementById('provider_id').value;
       window.location.href="http://localhost/month_view.php?u_org_pro_id=" + providerId;
    }

    </script>
    </head>
    <body>
     <table>
       <tr><td>

       <select name= "year" onchange="javascript:YearChange();">
         <?
            
    //dynamic year dropdown 14 years (4 back, current and 9 forward)
        
    year_only($year);
         
    ?>
        </select>
     
          
        <select name= "user_id" onchange="javascript:ProChange();">
           <?
           
    //display information based on selected year, month and user
           
    display_info($year$month$user);     
           
    ?>
        </select>

    </td>
    </tr>
    </table>
    </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •