开发者

send value one page to another page by using html and php

I need to send 3 text box and one drop down value to a different page,I can not use the submit button i have to use the image. code:-

<table width="70%" border="0" align="right" cellpadding="0" cellspacing="5">
    <tr>
      <td width="11%" align="right" valign="middle" class="text6">Type:</td>
      <td width="12%" align="right" valign="middle" >
      <select name="type">
          <option value="Alumni">Alumni</option>
          <option value="Student">Student</option>
          <option value="Faculty">Faculty</option>    
      </select></td>
      <td width="7%" align="right" valign="middle" class="text6">Name</span>:</td>
      <td width="22%" align="right" valign="middle"><input type="text" name="name" id="name"  style="width:130px;"/></td>
      <td width="8%" align="right" valign="middle"class="text6" >Course/Department:</td>
      <td width="14%" align="right" valign="middle" ><input type="text" name="course"  style="width:9开发者_运维知识库0px;"/></td>
      <td width="5%" align="right" valign="middle"class="text6">Year:</td>
      <td width="12%" align="right" valign="middle"><input type="text" name="year" style="width:80px;"/></td>
      <td align="right" valign="middle"><a href="searchprocess.php?&name=value"><img src="images/search_box.jpg" width="60" height="25" border="0" align="middle" style="border: solid 1px #CCCCCC;" /></a></td>
    </tr>
</table>


By adding more INPUT elements to the FORM. The browser will then add more key-value-pairs to the query string.


Side note: Using anchor tag to submit form values is not recommended, better to use submit buttons.

But here's the answer: Use javascript. E.g.

<html>
...
<script type="text/javascript">
  function redirectWithValues() {
    var sStr = "../base/test.jsp?TEXT1=" + encodeURI(document.frmTest.TEXT1.value)
     + "&TEXT2=" + encodeURI(document.frmTest.TEXT2.value)
     + "&TEXT3=" + encodeURI(document.frmTest.TEXT3.value)
     + "&OPTION1=" + encodeURI(document.frmTest.OPTION1.value);

    window.location.href = sStr;
    return false;
  }
</script>
...
<form name="frmTest" action="../base/test.jsp">
  <input type="text" name="TEXT1" value="Value1" />
  <input type="text" name="TEXT2" value="Value2" />
  <input type="text" name="TEXT3" value="Value3" />
  <select name="OPTION1">
    <option value="OptionValue1">Option Description 1</option>
    <option value="OptionValue2">Option Description 2</option>
    <option value="OptionValue3">Option Description 3</option>
  </select>

  <a href="#" onclick="return redirectWithValues()">Woe is me</a>
</form>
...
</html>


You can use <input type="image" ... /> instead of a submit button.


New answer

Your original page can use the code you specified

<Form method="post" action="page2.php">
code for your table here....

<!--Submit Button as Image-->
<input type="image" src="images/yourimage.gif" alt="Submit Form" name="submit" />
</form>

page2.php could look something like this:

<html>
<body>

<?php
$type = $_POST['type'];
$name = $_POST['name'];
$course = $_POST['course'];
$year = $_POST['year'];

echo $type;

etc etc

?>
</body>
</html>

If you want to display it in a text box etc you would need to do something similar to this:

<input type="text" name="course" value="<?php echo $course; ?>" />

Original answer

Just submit the form using POST and handle the query string with some PHP on the next page.

This is assuming the data is not sensitive. I'd prefer PHP over Javascript (where possible).

Not sure your question is totally clear on what you are trying to do, and what technologies/languages are available to you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜