|
-
Jun 26th, 2008, 08:23 AM
#1
Thread Starter
Hyperactive Member
how to change values in the input fields?
hello!
how to use php to change values of text field,checkbox,select box?
Ex: I have this code:
<select name="day"><option name="1">1</option><option name="2">2</option></select>
what is the php code to change the current selected item in the select box to make 2 for example?
thx
-
Jun 26th, 2008, 08:34 PM
#2
Frenzied Member
Re: how to change values in the input fields?
If you want to do it "live" then use JavaScript.
For setting it when the page are being build do sth like
<select name="day">
<option name="1" <?php echo("selected='selected'"); ?>>1</option>
<option name="2">2</option>
</select>
-
Jun 26th, 2008, 08:49 PM
#3
Thread Starter
Hyperactive Member
Re: how to change values in the input fields?
that's dosn't solve the problem. The Problem is as following:
I wrote a register.php page to register new members but the problem is when the user enter incorrect info like email that is already in the database the register page will display again with a message "duplicate email, choose another" but all of the field are cleared, So he/she have to rewrite info from the begining. So I want to copy the correct data to the fields automatically. I succes in doing that with textfield by write <input name="t" value=$_POST['t']> but with the checkbox and listbox I didn't until now 
thx
-
Jun 26th, 2008, 09:08 PM
#4
Frenzied Member
Re: how to change values in the input fields?
just gonna write "pseudo" code ok?
Code:
if (...posted...) {
$email = $_POST['email'];
$this= $_POST['that'];
$option= $_POST['option'];
.... check if all values are valid, if not dont call function that do the job, but display error like...:
$error = check_email($email);
}
<div><?php echo($error); ?></div>
<input type='text' name='email' id='email' value='<?php echo($email);> ' />
<input type='text' name='email' id='email' value='<?php echo($email);> ' />
<select name='option' id='option'>
<option id='eat' name='eat' <?php if($option=="eat") echo("selected='selected'"); ?>EAT</option>
<option id='drink' name='drink' <?php if($option=="drink") echo("selected='selected'"); ?>DRINK</option>
</select>
-
Jun 27th, 2008, 05:29 AM
#5
Thread Starter
Hyperactive Member
Re: how to change values in the input fields?
thx bro it was a good solution for the birthdate listboxes because I using for loop to fill the list of day,month,year with the numers.
But it is very bad solution for the list of the countries?! I have more than 100 name so it is would be so difficult to add a php statement proper to each of the 100 country?! so there is any way to select the item automatically by java or php?
2nd Question:
I used this to recover the state of the checkbox:
if(!isset($_POST['sharemail'])){
echo "checked='checked'";
}else{
echo ($_POST['sharemail']=="on")?"checked='checked'":"";
}
but is don't works why?
thx
-
Jun 28th, 2008, 12:03 AM
#6
Re: how to change values in the input fields?
PHP Code:
<select name="country"> <?php foreach ($countries as $country): ?> <?php if ($country == $selected_country): ?> <option value="<?php echo $country; ?>" selected="selected"><?php echo $country; ?></option> <?php else: ?> <option value="<?php echo $country; ?>"><?php echo $country; ?></option> <?php endif; ?> <?php endforeach; ?> </select>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|