Solved

select option..

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

867 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

21 Experts available now in Live!

Get 1:1 Help Now