Solved

select option..

Posted on 2007-03-20
2
196 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 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