如何使用onchange替换提交按钮 [英] How do I replace a submit button with onchange

查看:83
本文介绍了如何使用onchange替换提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于sql查询的列表和一个发布所选项目的提交按钮。页面上的其他项目链接到另一个查询并根据选择列表中选择的内容显示。



我想用onchange事件替换Submit按钮选择列表。



我创建了一个捕获var的函数,但是当我选择任何东西时,没有任何反应。



我如何获得查询的物种?



我缺少什么?我已经包含了一些精简代码来显示文件的相关部分。



有两个查询 - 一个用于选择列表,另一个用于显示数据在页面的其余部分。请忽略任何无关或邋code的代码,我会在以后清理它。



我尝试过的:



I have a list based on a sql query and a Submit button which posts the selected item. Other items on the page are linked to another query and display according to what is selected in the select list.

I want to replace the Submit button with the onchange event on the select list.

I created a function to capture the var, but when I select anything, nothing happens.

How do I get the "species" to the queries?

What am I missing? I’ve included some stripped-down code to show the relevant portions of the file.

There are two queries – one for the select list and the other to display data on the rest of the page. Please ignore any extraneous or sloppy code, I will clean it up later.

What I have tried:

mysql_select_db($database_PaSiteGuide, $PaSiteGuide);
$query_rsSelectSpeciesAlpha = "SELECT BirdsOfPA.ID, BirdsOfPA.CommonName FROM BirdsOfPA ORDER BY BirdsOfPA.CommonName ASC";
$rsSelectSpeciesAlpha = mysql_query($query_rsSelectSpeciesAlpha, $PaSiteGuide) or die(mysql_error());
$row_rsSelectSpeciesAlpha = mysql_fetch_assoc($rsSelectSpeciesAlpha);
$totalRows_rsSelectSpeciesAlpha = mysql_num_rows($rsSelectSpeciesAlpha);

$colname_rsBirdsOfPa = "-1";
if (isset($_POST['Species'])) {
  $colname_rsBirdsOfPa = $_POST['Species'];
}

mysql_select_db($database_PaSiteGuide, $PaSiteGuide);
$query_rsBirdsOfPa = sprintf("SELECT * FROM birdsofpa WHERE birdsofpa.ID = %s", GetSQLValueString($colname_rsBirdsOfPa, "int"));
$rsBirdsOfPa = mysql_query($query_rsBirdsOfPa, $PaSiteGuide) or die(mysql_error());
$row_rsBirdsOfPa = mysql_fetch_assoc($rsBirdsOfPa);
$totalRows_rsBirdsOfPa = mysql_num_rows($rsBirdsOfPa);
?>

<head>

<script>
function mySpeciesFunction() {
    var species= document.getElementById("Species").value;
}
</script>

</head>


<body>
<p align="center" class="BlackHeadline">Birds of Pennsylvania - An Annotated List</p>

<table width="1000" border="0" align="center">
  <tr>
    <td width="645" align="center" valign="bottom" bgcolor="#F2DB9B">

    <form action="TestBirdsOfPaPageAlpha.php" method="post" name="form1" target="_self" id="form1">
    <label for="Species" class="MediumSerifText">Select Species (Alphabetical order):</label>
    <select name="Species" id="Species" onchange="mySpeciesFunction()">
    <?php
do {  
?>
        <option value="<?php echo $row_rsSelectSpeciesAlpha['ID']?>"><?php echo $row_rsSelectSpeciesAlpha['CommonName']?></option>
        <?php
} while ($row_rsSelectSpeciesAlpha = mysql_fetch_assoc($rsSelectSpeciesAlpha));
  $rows = mysql_num_rows($rsSelectSpeciesAlpha);
  if($rows > 0) {
      mysql_data_seek($rsSelectSpeciesAlpha, 0);
	  $row_rsSelectSpeciesAlpha = mysql_fetch_assoc($rsSelectSpeciesAlpha);
  }
?>
      </select>
      </span>
      </form></td>
  <tr align="center" bgcolor="#F2DB9B">
    <td colspan="4"><table width="1000" border="1" align="center" cellpadding="5">
        <tr>
          <td colspan="3" align="center" bgcolor="#FFFFFF" class="BlackHeadline2"> <span class="BlackHeadline"><?php echo $row_rsBirdsOfPa['CommonName']; ?> (<em><?php echo $row_rsBirdsOfPa['SciName']; ?></em>)</span></td>
        </tr>
        <tr>
          <td colspan="2" rowspan="4" align="left" valign="top" bgcolor="#FFFFFF" class="smallSerif"><table width="400" border="1">
            <tr>
              <td width="250"><span class="MediumSerifText"><span id="sprytrigger2">Abundance</span>:</span></td>
              <td align="center"><span class="MediumText"><?php echo $row_rsBirdsOfPa['Abundance']; ?></span></td>
            </tr>





我的尝试:



---



What I have tried:

---

推荐答案

database_PaSiteGuide,
database_PaSiteGuide,


PaSiteGuide );
PaSiteGuide);


query_rsSelectSpeciesAlpha = SELECT BirdsOfPA.ID,BirdsOfPA.CommonName FROM BirdsOfPA ORDER BY BirdsOfPA.CommonName ASC;
query_rsSelectSpeciesAlpha = "SELECT BirdsOfPA.ID, BirdsOfPA.CommonName FROM BirdsOfPA ORDER BY BirdsOfPA.CommonName ASC";


这篇关于如何使用onchange替换提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆