Solved

select option..

Posted on 2007-03-20
2
179 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
Comment Utility
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
Comment Utility
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now