Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 1st, 2005, 06:52 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default concatinating values in textbox

I have a problem with this code.

I am trying to perform validation on the three drop down menus which give the DATE, MONTH and the YEAR.

I am putting the values of each into a hidden text box then
performing validation on the text box.

However, i need to allow the user to change the drop down value (by pulling it down and
selecting a value) and change the textbox automatically.

It works if i select 1 date, 1 month then 1 year. But, if i change the year, month or date again it just adds
to the textbox.

for example,

works: 6/6/2005

then if i change the year again (without a refresh of the page) the box reads:

6/6/20052004

How can i stop this?

Help appreciated.

Code:
// Check the INFANT Birthday
// 2 Year Old Check

function checkBirthday(obj)
 {
    if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(obj.value) ) {
        alert( "Invalid date supplied - must be format DD/MM/YYYY" );
        //obj.focus();
        return;
    }

    var d = new Date();
    var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);

    var diff = d.getDiff(d2, "y")
    if( isNaN(diff) ) {
        alert( "Invalid date supplied" );
    }
    else if( diff < 2 ) {
        alert( "This IS an INFANT \n they are younger that 2" );
        infant = true;
        document.form.submit();

    }
    else if( diff > 2 ) {
        alert( "This is NOT an INFANT \n they are older that 2" );
        infant = false;
        document.form.birthday.value = "";
        document.form.date.focus();
    }

}


<form name="form" action="abc.htm">
INF:<select name="date"
onChange="document.form.birthday.value=document.form.birthday.value+document.form.date.options[document.form.date.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
<%
    Response.write "<option> --- </option>"
For d = 01 to 31
    Response.write "<option value=" & d & "/>" & d & "</option>"
Next
%>
</select>
<select name="month"
onChange="document.form.birthday.value=document.form.birthday.value+document.form.month.options[document.form.month.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
<%
    Response.write "<option> --- </option>"
For m = 01 to 12
    response.Write "<option value=" & m & "/>" & MMtoMMM(m) & "</option>"
Next
%>        
</select>
<% 
Dim three_years_ago
three_years_ago = year(date) - 3
%>
<select name="year"
onChange="document.form.birthday.value=document.form.birthday.value+document.form.year.options[document.form.year.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
<%
    Response.write "<option> --- </option>"
For y = three_years_ago to year(date)
    Response.Write "<option value=" & y & ">" & y & "</option>"
Next
%>
</select>

<input type="text" name="birthday" size="5" style="font:7pt;" value="" maxLength="10"> 

<img src="images/required.gif"  onclick="javascript: checkBirthday(document.form.birthday);" value="Confirm">
</form>
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
  #2 (permalink)  
Old July 1st, 2005, 09:29 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

http://www.codingforums.com/showthread.php?t=62559

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum Textbox Values Snuffles ASP.NET 2.0 Basics 1 April 13th, 2007 01:36 PM
Taking values from textbox derekl ASP.NET 1.0 and 1.1 Professional 3 February 20th, 2006 08:30 AM
Problem Concatinating nText flyin SQL Server 2000 6 January 8th, 2006 03:25 PM
textbox with numerical values must C# 1 August 7th, 2003 12:44 PM



All times are GMT -4. The time now is 10:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.