Forum Moderators: open

Message Too Old, No Replies

Passing data to hidden input

month+day+year=yyyymmdd

         

bshaffer

4:39 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



Im a noob so please excuse me if this doesn't make sense.
I need the startdate to be yyyymmdd from the startmonth,startday and the startyear. Is there a script I can use, Ive searched everywhere for an answer for this. Thanks for the help

<input name="startdate" value="NEED IT TO SAY YYYYMMDD"type="Hidden"

<span class="style11">
<div class="form-row"><label><span class="row-title">
<span class="style11">Beginning </span></span>
<select name="startmonth" size="1" class="style11">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select><span class="style11">/
</span>

<select name="startday" size="1" class="style11">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>

<select name="startyear" size="1" class="style11">
<option value="2009" selected="1">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>

coopster

6:21 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, bshaffer.

You just need to put the pieces together when any of the selections are changed. You can use an "onchange" event handler for each of the select elements. It may be easier if you use an identifier on each element too, for example ...

<input id="startdate" name="startdate" value="" type="hidden"> 
<select id="startmonth" name="startmonth" size="1" class="style11">

Then you can add a function that watches for each element to change:
document.getElementById('startmonth').onchange = changeMyHiddenField;

Create yourself a
changeMyHiddenField
function that modifies the element with the
startdate
id and you are good to go.

Don't forget, you will still want to piece this together on the server side in case your user does not have JavaScript enabled in their browser!

bshaffer

7:10 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



You will have to excuse my ignorance but like I said I'm a noob and I'm not very familiar with JavaScript.I'm trying to setup a payment form so people from the church can make recurring donations through the website using linkpoint connect and they need the startdate to be hidden in yyyymmdd format.I have added the id=" "to startdate, startmonth, startday,startyear then you kinda lost me after that. Could you please elaborate a bit further for me. I really appreciate the help.THANKS

rocknbil

8:03 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



make recurring donations through the website using linkpoint connect and they need the startdate to be hidden in yyyymmdd format.

I work with Linkpoint/FirstData/Elavon/ whatever-they-are-calling themselves these days - is there a particular reason you are forced to use Javascript for this?

The reason I ask is that if JS is disabled, it won't work, and your server-side processing can do this much easier and reliably. Are you posting DIRECTLY to linkPoint or are you using a submit script on your side, such as a PHP script?

I strongly recommend against making it Javascript dependent, but if you are posting directly to the gatway and see no other way, start with adding onChange handlers to each select.

<input name="startdate" id="startdate" value=""type="Hidden">

<select name="startmonth" id="startmonth" class="style11" onChange="calcDate();">
....

<select name="startday" id="startday" size="1" class="style11" onChange="calcDate();">
.....

<select name="year" id="startyear" size="1" class="style11" onChange="calcDate();">
.....

Now somewhere in your document, or in external javascript,


<script type="text/javascript">
function calcDate () {
var mm = document.getElementById('startmonth');
var dd = document.getElementById('startday');
var yy = document.getElementById('startyear');
var startdate = yy.options[yy.selectedIndex].value +
mm.options[mm.selectedIndex].value +
dd.options[dd.selectedIndex].value;
document.getElementById('startdate').value=startdate;
// uncomment to test
//alert(document.getElementById('startdate').value);
}
</script>

This code is untested, but it should get you started. Also it has no error checking to make sure a valid date is submitted, and like I said, this should be duplicated server side, but LinkPoint will kick it back if invalid data is supplied, so you might squeak by without those.

bshaffer

8:34 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



Well I created a test form here <snip> and I thought that was the only way to go.The user adds their info then it goes straight to linkpoint.I'm really not sure how to do it any other way. Im open to suggestions and how to do it though.

[edited by: eelixduppy at 2:31 pm (utc) on April 13, 2009]
[edit reason] no URLs, please [/edit]