Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Date input conversion with CWP

Featured Replies

  • Newbies

Hi - I'm getting to grips with FMSA custom web publishing and have a question regarding the conversion of a input date field on a form, from dd/MM/yyyy, to the standard "fm" format of MM/dd/yyyy. I've researched enough to realise this should be done client side with JavaScript but my javascript skills aren't that advanced. Does anyone know how to achieve this?

So far I figure that the date field submitted to the database (Booking Date in MM/dd/yyyy format), should be a hidden input field on the form. Then on submitting the form, the field the user completed, tempDate (in dd/MM/yyyy format) should be converted using javascript to MM/dd/yyyy and copied to the Booking Date field.

The other complication is that there are several forms which contain the different products the user may choose to book, not just a single form with one product.

Each form is named according to the following:

<xsl:attribute name="name">prodform<xsl:value-of select="$record/fmrs:field[@name = 'ID']/fmrs:data[1]"/></xsl:attribute>

which creates forms named prodform2001, prodform2002, prodform2003 etc depending on the catalogue ID.

The xsl file has the form defined as:-

<form method="POST">

<xsl:attribute name="action">bookedOK.xsl</xsl:attribute>

<xsl:attribute name="name">prodform<xsl:value-of select="$record/fmrs:field[@name = 'ID']/fmrs:data[1]"/></xsl:attribute>

<input type="hidden" name="-db" value="Booking"/>

<input type="hidden" name="-lay" value="web"/>

<input type="hidden" name="Booking Date" />

... how do I fill out the Booking Date field with MM/dd/yyyy values?...

<input type="hidden" name="-new" value=""/>

... display what's on sale...

<table width="582" border="0" cellspacing="2" cellpadding="2">

<tr><td><xsl:value-of select="$record/fmrs:field[@name = 'Products::ProductName']/fmrs:data[1]"/></td>

... temporary input field for Booking Date in dd/MM/yyyy format

<td><input type="text" name="tempDate" /></td></tr>

</table>

</form>

I'd be grateful for any suggestions on the best way to do this from within an xsl template file.

As an aside, the conversion of booking dates when displayed on the webpage has been done by using an xslt function and seems to work well:

<xsl:for-each select="fmrs:field[@name = 'Booking Date']/fmrs:data[1]">

<xsl:value-of select="fmxslt:convert_datetime('MM/dd/yyyy','EEE dd/MM/yy',.)"/>

</xsl:for-each>

Thanks for any help you can give me and cheers...

Hi, d! Welcome to FMFORUMS! Now, until someone posts exactly what you want (I'm afraid I haven't delved into xml/xsl yet and my JS is probably worse than yours), can you use FM to parse your date and re-arrange the components using CALC fields?

--ST

You can use some Javascript to reformat the date fefore the Form is submitted.

<html><head>

<script>

function moddate()

   {

   formdate = document.myform.mydate.value.split("/");

   document.myform.mydate.value = formdate[1] + "/" + formdate[0] + "/" + formdate[2];

   document.myform.submit();

   }

</script>

</head>

<body><form name="myform" action="FMPro" method="POST" onsubmit="moddate(); return false;">

<input type="hidden" name="-db" value="mydb.fp5">

<input type="hidden" name="-format" value="mypage.html">

Enter date (dd/mm/yyyy): <input type="text" name="mydate" value="">

<input type="submit" name="-new" value="Submit Form">

</form></body></html>

Good Luck.

Garry

  • 3 weeks later...
  • Author
  • Newbies

Thanks Steve T for the suggestion!

  • Author
  • Newbies

Garry - cheers for this. Have ended up using your method. Many thanks!!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.