Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2005, 10:20 AM
Friend of Wrox
 
Join Date: Jan 2005
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
 
Old July 3rd, 2005, 03:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old July 7th, 2005, 06:53 AM
Friend of Wrox
 
Join Date: Jan 2005
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





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





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