Article View: adobe.golive.dynamic.content
Article #63Re: Formatting a user input date
From: Patrick_Schreifels
Date: Thu, 08 Jul 2004 07:31
Date: Thu, 08 Jul 2004 07:31
26 lines
2481 bytes
2481 bytes
Jeremy,
The reason why it stops working is because you are explicitly naming the fields, then when you bind the fields to the MySQL database GoLive graciously re names your fields to something it likes. That's why I agree with Jerry, use server side validation where ever possible. If you want to do this on the client side, then here's the work around:
Keep your three drop down lists, but add a hidden field. Now include this JavaScript (this assumes that you've added the hidden field directly after the three drop down lists... very important):
function makeDate()
{
var mm = document.FormName.elements[0].value;
var dd = document.FormName.elements[1].value;
var yyyy = document.FormName.elements[2].value;
// you may have to convert the numbers to strings, but it worked for me as is.
document.FormName.elements[3].value=(yyyy+mm+dd);
}
Select each drop down list form element (in the layout view) and add the GoLive action 'Call Function' for the 'Text Change' event, which is located under the 'Specials' sub-menu of the Action menu of the Actions palette, choosing 'makeDate' from the function drop down list.
Now bind only the hidden field to the date field in your database, not the drop down lists! Set your submit button action to Add Record, save it, and test it out.
The reason this works is because in our JavaScript, we are not explicitly addressing each form element. This breaks when we bind to the database. We are instead addressing them by the order they appear on the page. This is why its important to make sure the order is correct.
If for some reason your date is screwed up when it gets inserted, comment out the line where we concatenate the date string and add:
alert(yyyy+mm+dd);
that way you can see how its built without adding a record.
Technical Details
Message-ID:
<3bb4c65d.13@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!easynews.net!easynet-isham!easynet.net!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<3bb4c65d.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: 11ffd2,8502de635f9b659d X-Google-Attributes: gid11ffd2,public X-Google-Language: ENGLISH,ASCII-7-bit From: Patrick_Schreifels@adobeforums.com Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!easynews.net!easynet-isham!easynet.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.golive.dynamic.content Subject: Re: Formatting a user input date Message-ID: <3bb4c65d.13@webx.la2eafNXanI> Date: Thu, 8 Jul 2004 00:31:42 -0700 References: <3bb4c65d.-1@webx.la2eafNXanI> Lines: 42 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit