Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Retain selected values of a date dropdown list after submit button is clicked
Old 05-05-2010, 11:34 AM Retain selected values of a date dropdown list after submit button is clicked
Junior Talker

Posts: 1
Trades: 0
1. I would like to get my date of birth (day:, month:, year drop down to retain selected values after submit button has been clicked and validation for something else on the same form has failed so user won't need to choose date of birth again.

2. I would also like to create a validation script for it using php not javascript.


This is how I got my gender drop down to retain selected values after signup button was clicked and something else on my form failed validation
HTML Code:
<tr> 
<td>I  am</td> 
<td> 
<select name="sex" class="select"  id="sex" > 
 <option value="0" <?php if  (isset($_POST['sex']) && $_POST['sex'] == 0) { 
  echo  'selected="selected"';} ?> >-Gender-</option> 
   <option value="1" <?php if (isset($_POST['sex']) &&  $_POST['sex'] == 1) { 
 echo 'selected="selected"';}  ?>>Male</option> 
  <option value="2" <?php if  (isset($_POST['sex']) && $_POST['sex'] == 2) { 
  echo  'selected="selected"';} ?>>Female</option> 
   </select> 
  </td></tr>
I would like to do the same with my birthday selection drop down and here is the code on my homepage:

HTML Code:
<tr>  
 <td>Birthday</td> 
 <td> 
<?php 
require_once('includes/bdayselect/bdayselect.php');  
$myCalendar = new tc_calendar("dob", true); 
//  $myCalendar->setIcon("http://www.webmaster-talk.com/images/iconCalendar.gif"); 
$myCalendar->setDate(01,  03, 1900); 
$myCalendar->setPath("./"); 
$myCalendar->setYearInterval(1900,  2010); 
$myCalendar->dateAllow('1900-01-01', '2010-12-31'); 
//$myCalendar->setHeight(350);   
//$myCalendar->autoSubmit(true, "form1"); 
$myCalendar->writeScript();  
?> 
 
 
</td>
and here is the code on my birthday script page:
HTML Code:
//write the select box of days 
function  writeDay(){ 
echo("<select name=\"".$this->objname."_day\"  id=\"".$this->objname."_day\"  onChange=\"javascript:tc_setDay('".$this->objname."',  this[this.selectedIndex].value, '$this->path');\"  class=\"tcday\">"); 
echo("<option  value=\"00\">Day:</option>"); 
for($i=1; $i<=31; $i++){ 
$selected  = ((int)$this->day == $i) ? " selected" : ""; 
echo("<option  value=\"".str_pad($i, 2 , "0",  STR_PAD_LEFT)."\"$selected>$i</option>"); 
} 
echo("</select>  "); 
} 
 
//write the select box of months 
function  writeMonth(){ 
echo("<select name=\"".$this->objname."_month\"  id=\"".$this->objname."_month\"  onChange=\"javascript:tc_setMonth('".$this->objname."',  this[this.selectedIndex].value, '$this->path');\"  class=\"tcmonth\">"); 
echo("<option  value=\"00\">Month:</option>"); 
 
$monthnames =  $this->getMonthNames(); 
for($i=1; $i<=sizeof($monthnames);  $i++){ 
$selected = ((int)$this->month == $i) ? " selected" : ""; 
echo("<option  value=\"".str_pad($i, 2, "0",  STR_PAD_LEFT)."\"$selected>".$monthnames[$i-1]."</option>"); 
}  
echo("</select> "); 
} 
 
//write the year textbox 
function  writeYear(){ 
//echo("<input type=\"textbox\"  name=\"".$this->objname."_year\" id=\"".$this->objname."_year\"  value=\"$this->year\" maxlength=4 size=5  onBlur=\"javascript:tc_setYear('".$this->objname."', this.value,  '$this->path');\" onKeyPress=\"javascript:if(yearEnter(event)){  tc_setYear('".$this->objname."', this.value, '$this->path');  return false; }\"> "); 
echo("<select  name=\"".$this->objname."_year\" id=\"".$this->objname."_year\"  onChange=\"javascript:tc_setYear('".$this->objname."',  this[this.selectedIndex].value, '$this->path');\"  class=\"tcyear\">"); 
echo("<option  value=\"0000\">Year:</option>"); 
I would appreciate all help given..
This is something i've been trying to get my head around for ages..
Done multiple forum searches..

So far i'm happy because a few weeks ago I didn't think i would be able to code using php. Now i've just about finished a registration section of my website.
Thanks in advance.

Last edited by chrishirst; 05-05-2010 at 12:19 PM..
redone is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-05-2010, 12:27 PM Re: Retain selected values of a date dropdown list after submit button is clicked
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.tizag.com/phpT/examples/formex.php

http://www.homeandlearn.co.uk/php/php4p9.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Retain selected values of a date dropdown list after submit button is clicked
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28195 seconds with 12 queries