By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,054 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,054 IT Pros & Developers. It's quick & easy.

question about displaying select and radio button

P: 54

i have registration form where user selects from a drop down to select their area code apart from filling other details in the form. in the next page which is a confirmation page i would like to display the select option that a user choose in the first page i am able to display this using a textfield however i would like to display using the select drop down.

following is the code for both select and radio button that i have used.

1. Select tag

$pcontactnumber = addslashes($_POST["pcontactnumber"]);

<select name="pcontactnumber">
<option value="09"> <?php if $pcontactnumber == "09" echo "selected" ?>09</option>
<option value="07"> <?php if $pcontactnumber == "07" echo "selected" ?>07</option>

2. radio button
<script language="javascript">

var m = document.confirmregistrationform.gender.Male.check ed;
var f = document.confirmregistrationform.gender.Female.che cked;

echo "<input type =\"radio\" name=\"gender\" value=\"Male\" if($gender=='Male') m // Male";
echo "<input type =\"radio\" name=\"gender\" value=\"Female\" if($gender=='Female') f // Female";

2. radio button
echo "<input type =\"radio\" name=\"gender\" value=\"Male\" if($gender=='Male') {gender.checked}>Male";
echo "<input type =\"radio\" name=\"gender\" value=\"Female\" if($gender=='Female') {gender.checked}>Female";

please correct the code and provide the correct syntax to display the information for select tag and radio button in the confirmation page using php

also i have another question, how can i pass a variable to a php file when a user clicks on a link without submitting a form
Please choose your user name <input type="text" name="username"> <a href="checkusername.php">check availability</a>

i have tried document.myform.submit(); onclick event for the <a> tag however it does not work

please advice.

Jan 1 '08 #1
Share this Question
Share on Google+
1 Reply

P: 3
is the select tag that you give us is in confirmation page?
if yes, you must get the variabel that passing from registration form, i think it can be like this..

in registration form :
<select name="pcontactnumber">
<option value="09"> 09</option>
<option value="07"> 07</option>

in confirmation page :
<select name="pcontactnumber">
$pcontnumber = $_POST["pcontactnumber"];
<option value="09" <? if ($pcontnumber == "09") echo "selected" ?> > 09 </option>
<option value="07" <? if ($pcontnumber == "07") echo "selected" ?> > 07 </option>

u can try like that.
for second quest. u can use this :
<a href="something_page.php?variablename=variablevalu e">link</a>

exp :
<a href="check.php?id=2">link</a>

be sure "=" and "?" sign cant have a space in left and right... check.php?id=2
Jan 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.