?
Solved

select option..

Posted on 2007-03-20
2
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 800 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 1200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Find out what you should include to make the best professional email signature for your organization.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…
Suggested Courses

777 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