Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic 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, 10:20 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 maxLength property

Code:
<input type="text" name="birthday<%=k%>" size="5" style="font:7pt;" value="" maxLength="10">
As per the code above i am experiancing problems with the maxLength property.

This code is adding to the textbox every time it is changed and it disregards the maxLength setting. How can i combat this?

Code:
onChange="document.form.birthday.value=document.form.birthday.value+document.form.date.options[document.form.date.selectedIndex].value;"

Regards,

Picco

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 3rd, 2005, 03:57 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think scripted additions ignore the maxLength value. Change the onchange handler to use a function to make it tidier and chnage it to:
Code:
<select onchange="showInTextbox(this.options[this.selectedIndex].value);" ...>

function showInTextBox(Text)
{
  var oText = document.form.birthday;
  var sText = oText.value + Text;
  var sNewText = sText.substr(sText.length - oText.maxLength);
  oText.value = sNewText;
  //or as stated below:
  //document.form.birthday.value = Text;
}
I'm not sure why your code actually works at all as the text box is named "birthday<k>", whatever the server side value of k is.
And if your date is in the format "dd/mm/yyyy" and you want to limit the length to 10 why not just overwrite the old value everytime, why append to what's there already?

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old July 7th, 2005, 06:53 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

Code:
 
<select name="chddate<%=j%>"
onChange="document.form.chdbirthday<%=j%>.value=document.form.chddate<%=j%>.options[document.form.chddate<%=j%>.selectedIndex].value+document.form.chdmonth<%=j%>.options[document.form.chdmonth<%=j%>.selectedIndex].value+document.form.chdyear<%=j%>.options[document.form.chdyear<%=j%>.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;"> 



<%
        Response.write "<option> --- </option>"
For d = 1 to 31
    if len(d) = 1 then
        Response.Write "<option value=0"& d & ">" & d & "</option>"
    else
        Response.write "<option value=" & d & ">" & d & "</option>"
    end if
Next
%> 
</select> 
<select name="chdmonth<%=j%>"
onChange="document.form.chdbirthday<%=j%>.value=document.form.chddate<%=j%>.options[document.form.chddate<%=j%>.selectedIndex].value+document.form.chdmonth<%=j%>.options[document.form.chdmonth<%=j%>.selectedIndex].value+document.form.chdyear<%=j%>.options[document.form.chdyear<%=j%>.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;"> 




<%
    Response.write "<option> --- </option>"
For m = 1 to 12

    if len(m) = 1 then
        Response.write "<option value=0"& m & ">" & MMtoMMM(m) & "</option>"
    else
        Response.Write "<option value=" & m & ">" & MMtoMMM(m) & "</option>"
    end if


Next
%> 
</select> 
<% 
Dim vor_15_jahren 
vor_15_jahren = year(date) - 15
%> 
<select name="chdyear<%=j%>"
onChange="document.form.chdbirthday<%=j%>.value=document.form.chddate<%=j%>.options[document.form.chddate<%=j%>.selectedIndex].value+document.form.chdmonth<%=j%>.options[document.form.chdmonth<%=j%>.selectedIndex].value+document.form.chdyear<%=j%>.options[document.form.chdyear<%=j%>.selectedIndex].value;"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;"> 

<%
    Response.write "<option> --- </option>"
For y = vor_15_jahren to year(date) -2
    Response.Write "<option value=" & y & ">" & y & "</option>"
Next
%> 
                </select> 

                <input type="hidden" name="chdbirthday<%=j%>" size="5" style="font:7pt;" maxLength="10">
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
VB .Net TextBox MaxLength Mocha Visual Studio 2005 1 October 10th, 2007 08:35 AM
textbox MaxLength akumarp2p C# 2005 1 December 27th, 2006 06:31 AM
Changing maxlength in JScript BrianWren Javascript How-To 2 June 20th, 2006 03:11 PM
textbox cutting off text? but maxlength is 10,000? ALEX_GRIM Classic ASP Basics 3 February 6th, 2005 08:47 AM
textbox Maxlength problem ashu_gupta75 Classic ASP Basics 5 May 6th, 2004 03:48 AM



All times are GMT -4. The time now is 08:37 AM.


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