Jump to content

Help running javascript function onchange and passing variables.


Darkmatter5

Recommended Posts

Here's my page code.

 

<?php
require('library/config.inc.php');
require('library/ecabinet_funcs.php');
$ec=new ecabinet();
$page_title="E-Cabinet Filing Page";

ob_start();
session_start();

if(!isset($_SESSION['member_id'])) {
	ob_end_clean();
	header("Location: index.php");
	exit();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
<link href="library/config.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function reloadCAB(form) {
    var cab=form.cab.options[form.cab.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab ;
    document.write("HELLO")
}
function reloadFOL(form) {
    var cab=form.cab.options[form.cab.options.selectedIndex].value;
    var fol=form.fol.options[form.fol.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab +'&fol=' + fol ;
    document.write("HELLO2")
}
</script>
</head>

<body>
<div id="wrap">
  <div id="header">
    <table width="100%" height="100%" align="center">
      <tr>
        <td width="50%" valign="bottom"><?php $ec->bannertext(); ?></td></td>
        <td align="right" valign="bottom"><?php echo date("F j, Y, h:i:s A"); ?></td>
      </tr>
    </table>
  </div>
  <div id="content">
    <div id="c_menu">
      <table width="100%">
        <td><?php $ec->user_rights(index); ?></td>
        <td align="right"><?php $ec->version(); ?></td>
      </table>
    </div>
    <div id="c_content">
      <?php
        $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
        mysql_select_db($dbnamemain);
        
        $cabid=$HTTP_GET_VARS['cab'];
        $folid=$HTTP_GET_VARS['fol'];
        // query for cabinets dropdown list
        $quer_cab=mysql_query("SELECT DISTINCT cabinet_id, cab_name FROM cabinets ORDER BY cab_name");
        // query for folders dropdown list
        if(isset($cabid) && strlen($cab)>0) { $quer_fol=mysql_query("SELECT DISTINCT fol_name FROM folders WHERE cabinet_id=$cabid ORDER BY fol_name"); }
        else { $quer_fol=mysql_query("SELECT DISTINCT fol_name FROM folders ORDER BY fol_name"); }
        // query for items dropdown list
        if(isset($folid) && strlen($fol)>0) { $quer_item=mysql_query("SELECT DISTINCT item_name FROM items WHERE folder_id=$folid ORDER BY item_name"); }
        else { $quer_item=mysql_query("SELECT DISTINCT item_name FROM items ORDER BY item_name"); }
        
        echo "<form method='post' name='f1'>
              <select name='cabinet_lst' onchange=\"reloadCAB(this.form)\">
              <option value='showall'>Show all</option>";
        while($cab=mysql_fetch_array($quer_cab)) { echo  "<option value='$cab[cabinet_id]'>$cab[cab_name]</option>"; }
        echo "</select><br>
              <select name='folder_lst' onchange=\"reloadFOL(this.form)\">
              <option value='showall'>Show all</option>";
        while($fol=mysql_fetch_array($quer_fol)) { echo  "<option value='$fol[fol_name]'>$fol[fol_name]</option>"; }
        echo "</select><br>
              <select name='item_lst'>
              <option value='showall'>Show all</option>";
        while($item=mysql_fetch_array($quer_item)) { echo "<option value='$item[item_id]'>$item[item_name]</option>"; }
        echo "cab: $cab, fol: $fol";
        echo "</form>";
        
        mysql_close($conn);
      ?>
    </div>
  </div>
  <div id="tools">
    <div id="tools_login" align="center"><?php $ec->login_tool(); ?></div>
    <div id="tools_account" align="center"><?php $ec->account_tool(); ?></div>
  </div>
  <div id="footer">
    <table width="100%" height="100%" border="0">
      <tr><td valign="bottom">Copyright &copy 2008 by ??.  All rights reserved.</td></tr>
    </table>
  </div>
</div>
</body>
</html>

<?php ob_end_flush(); ?>

 

The code produces my three dropdown lists correctly, but when a selection in any of them nothing happens.  According to my code, my intent was when Cabinet is changed the JS would output HELLO and if Folders is changed the JS would output HELLO2.  It does nothing.

 

After I get HELLO and HELLO2 working I'm wanting to get it to output the cab and fol variables.

 

Thanks in advance!

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-Cabinet Filing Page</title>
<link href="library/config.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function reloadCAB(form) {
    var cab=form.cab.options[form.cab.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab ;
    document.write("HELLO")
}
function reloadFOL(form) {
    var cab=form.cab.options[form.cab.options.selectedIndex].value;
    var fol=form.fol.options[form.fol.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab +'&fol=' + fol ;
    document.write("HELLO2")
}
</script>
</head>

<body>
<div id="wrap">
  <div id="header">
    <table width="100%" height="100%" align="center">

      <tr>
        <td width="50%" valign="bottom"><a href='res_checklist.php'>CHECKLIST</a></td></td>
        <td align="right" valign="bottom">December 3, 2008, 09:01:54 AM</td>
      </tr>
    </table>
  </div>
  <div id="content">
    <div id="c_menu">

      <table width="100%">
        <td><a href='help.php' tabindex='7'>HELP</a> | <a href='forums.php'>FORUMS</a> | <a href='res_filing.php'>FILING</a> | <a href='res_admin.php'>SITE ADMIN</a></td>
        <td align="right">E-Cabinet version:  1.2</td>

      </table>
    </div>
    <div id="c_content">
      <form method='post' name='f1'>
              <select name='cabinet_lst' onchange="reloadCAB(this.form)">
              <option value='showall'>Show all</option><option value='2'>Bills</option><option value='4'>Investments</option><option value='3'>MilitaryDocuments</option><option value='1'>unfiled</option><option value='5'>Vehicle</option></select><br>

              <select name='folder_lst' onchange="reloadFOL(this.form)">
              <option value='showall'>Show all</option><option value='Credit Card statements'>Credit Card statements</option><option value='Internet'>Internet</option><option value='John Hancock'>John Hancock</option><option value='Primerica'>Primerica</option><option value='Seperations forms'>Seperations forms</option><option value='Stocks'>Stocks</option><option value='Telephone'>Telephone</option><option value='Water and Electric'>Water and Electric</option></select><br>
              <select name='item_lst'>
              <option value='showall'>Show all</option><option value=''>inter01</option><option value=''>inter02</option><option value=''>Primerica transaction - 093008</option><option value=''>Stock1</option><option value=''>tel01</option><option value=''>tel02</option><option value=''>tel03</option><option value=''>tel04</option><option value=''>tel05</option></select><br></form>    </div>

  </div>
  <div id="tools">
    <div id="tools_login" align="center"><table width='100%' height='100%' valign='middle'>
                          <tr><td><b><span class='welcome_text'>Welcome <strong></b>mark.lalich</strong>!</span></td></tr>
                          <tr><td align='center'><span class='small_text'><a href='res_accmaint.php'>Edit your profile</a> | <a href='logout.php' tabindex='5'>Logout</a></span></td></tr>

                          </table></div>
    <div id="tools_account" align="center"><table width='100%' height='100%' valign='middle'>
                          <tr><td align='center'><span class='medium_text'>You have 2 message(s).</span></td></tr>
                          <tr><td align='center'><span class='small_text'><a href='res_maint.php' tabindex='7'>Maint</a> | <a href='help.php' tabindex='8'>Help</a> | <a href='res_mess.php'>My Messages</a></span></td></tr>
                          </table></div>

  </div>
  <div id="footer">
    <table width="100%" height="100%" border="0">
      <tr><td valign="bottom">Copyright &copy 2008 by ??.  All rights reserved.</td></tr>
    </table>
  </div>
</div>
</body>

</html>


 

Here you go, enjoy!  ;)

Link to comment
Share on other sites

you were using cab/fol instead of cabinet_list/folder_list. also, i recommend using alert() instead of document.write as document.write can go crazy when there is html already on the page:

 

<script type="text/javascript">
function reloadCAB(form) {
    var cab=form.cabinet_lst.options[form.cabinet_lst.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab ;
    alert("HELLO");
}
function reloadFOL(form) {
    var cab=form.cabinet_lst.options[form.cabinet_lst.options.selectedIndex].value;
    var fol=form.folder_list.options[form.folder_list.options.selectedIndex].value;
    //self.location='dd.php?cab=' + cab +'&fol=' + fol ;
    alert("HELLO2");
}
</script>

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.