Solved

select option..

Posted on 2007-03-20
2
202 Views
Last Modified: 2007-04-01
I am trying to send a vaule of select option in a.php to the another page's select option's value..

for example,
a.php file----
<form action = " a.php" >
<select name= "test">
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
</select>
</form>

b.php ----
<select name= "gettest">
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
</select>

if i select 1 in a.php page, on b.php, 1 has to be selected.
how can i send a value and recieve the value?
0
Comment
Question by:bbvic
2 Comments
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 200 total points
ID: 18760541
The values are send though the form the default method is get

so in this case you would do on b.php

<select name= "gettest">
<option value = "1" <?=($_GET["test"]==1?"selected":"")?>>1</option>
<option value = "2" <?=($_GET["test"]==2?"selected":"")?>>2</option>
<option value = "3" <?=($_GET["test"]==3?"selected":"")?>>3</option>
</select>

if you use the post method you would do $_POST["test"] instead of $_GET

<?=($_GET["test"]==1?"selected":"")?> is a if statement another way to write it would be

<? if($_GET["test"]==1) {

echo "selected";
} ?>
0
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 300 total points
ID: 18762003
Please check this a.php and b.php

a.php
**************************************************
<HTML>
<HEAD>
<TITLE>Raja's sample</TITLE>
</HEAD>

<BODY>
<form name="frmname" method="post" action="b.php">
<TABLE>
<TR>
      <TD>
      <select name= "test">
      <option value = "">Please select</option>
      <option value = "1">1</option>
      <option value = "2">2</option>
      <option value = "3">3</option>
      </select>
      </TD>
</TR>
<TR>
      <TD><input type="submit" name="btnbutton" value="Submit"></TD>
</TR>
</TABLE>
</BODY>
</HTML>

b.php
***************************************************************************
<?php
$selectedvalue=$_POST['test'];
?>
<HTML>
<HEAD>
<TITLE>Raja's sample</TITLE>
</HEAD>

<BODY>
<form name="frmname" method="post" action="">
<TABLE>
<TR>
      <TD>
      <select name= "test">
      <option value = "">Please select</option>
      <option value = "1" <?php echo $selectedvalue=="1"?"selected":""?> >1</option>
      <option value = "2" <?php echo $selectedvalue=="2"?"selected":""?>>2</option>
      <option value = "3" <?php echo $selectedvalue=="3"?"selected":""?>>3</option>
      </select>
      </TD>
</TR>
<TR>
      <TD></TD>
</TR>
</TABLE>
</BODY>
</HTML>

i hope this will help you.

Regards,
M.Raja
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql Query show error "SELECT statements have a different number of columns" 4 35
Undefined variable problem 5 23
ajax to record click 3 16
Reference key in foreach loop 4 22
This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question