Jump to content

<select onchange=


portabletelly

Recommended Posts

I have a form with a go button which echo's two variables for customer and tech when I submit the form. However my intention is to choose a tech in the select option "><select type="submit" name="ChooseTech" size="1" onChange="do somthing here"> then echo the content to the page without having to hit the go button.

 

I belive I need to use Onchange but not matter what I type in for onchange= nothing seems to happen. Ideally I would like to choose a tech from the dynamic list then call a function which outputs the contents under

echo $tech;

echo $customer;

 

Does anyone have any ideas how I could do that?

 

<html>
<head>
<title>Manage Queues</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Designed by Aaron Portelli" content="Portal HelpDesk">
<link rel="stylesheet" type="text/css" href="../style.css" />
 <?php
 include("connect.php");
 include("selectdb.php");
include("functions.php");
 ?>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100" border="0" cellspacing="0" cellpadding="1">
 <tr>
   <td width="25%"><b>Tech_Queue</b>   </td>

   <td width="25%"><b>Customer_Queue</b></td></td>
   <td></td>
 </tr>
 <tr>
   <td width="25%"><select type="submit" name="ChooseTech" size="1" onChange="do somthing here">
         <?PHP echo ChooseTech(); ?>
         </select></td>
   <td width="25%"><select name="ChooseCustomer" size="1" onChange="do somthing here">
         <?PHP echo createList(); ?>
         </select></td>
   <td width="50%"></td>
</table>
<br>
<input type="submit" name="command" value="GO!" class="button" />
</form>
<h1> </h1>
<?php
$tech = htmlspecialchars($_POST['ChooseTech']);
$customer = htmlspecialchars($_POST['ChooseCustomer']);
echo $tech;
echo $customer;
?>
</body>
</html>

Link to comment
Share on other sites

Give your form a name then do this

 

<select name="ChooseCustomer"  onChange="document.formname.submit()">

 

i think you will only be able to use this on the last select. But also if someone selects the last one first, it will submit.

 

Ray

Link to comment
Share on other sites

php is a server side script, so anytime you want to show new content on the page your have to "submit" what you want. With java, it is client side, so data gets stored in the browser and if you want to change content you can do so without submitting it back to the server for update.

 

Ray

Link to comment
Share on other sites

Not sure if this is going to work because the onchange is client side. What I now want to do is if a user chooses a tech <select name="ChooseTech"  onChange="document.ct.submit()"> then a mysql query is run which echo's the outputs pn the same page for all the calls for that tech.

 

Any idea how I would do that or if its possible?

 

<html>
<head>
<title>Manage Queues</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Designed by Aaron Portelli" content="Portal HelpDesk">
<link rel="stylesheet" type="text/css" href="../style.css" />
  <?php
  include("connect.php");
  include("selectdb.php");
include("functions.php");
  ?>
</head>
<body>

<table width="100" border="0" cellspacing="0" cellpadding="1">
  <tr>
    <td width="25%"><b>Tech_Queue</b>   </td>

    <td width="25%"><b>Customer_Queue</b></td></td>
    <td></td>
  </tr>
  <tr>
    <td width="25%"><form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="ct" method="post">
    <select name="ChooseTech"  onChange="document.ct.submit()">
            <?PHP echo ChooseTech(); ?>
          </select></form></td>

    <td width="25%"><form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="cc" method="post">
    <select name="ChooseCustomer"  onChange="document.cc.submit()">
          <?PHP echo createList(); ?>
          </select></form></td>
    <td width="50%"></td>
</table>
<br>
<input type="submit" name="command" value="GO!" class="button" />

<h1> </h1>
<?php
$tech = htmlspecialchars($_POST['ChooseTech']);
$customer = htmlspecialchars($_POST['ChooseCustomer']);
echo $tech;
echo $customer;
?>
</body>
</html>

Link to comment
Share on other sites

You need to submit the form to a script which runs your query. As you said, OnChange is client side, while php is server side. Hence, to run php scripts you'll need to make a new request to the server.

Link to comment
Share on other sites

There is not problem mixing javascript with php. The onchange is javescript so what you do is put a check to see if the form has been submitted.

 

<?php
if(isset($_POST['ChooseTech'])){
// Run mysql query below

} else {
// Show your original form below

}
?>

 

Ray

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.