Forum Moderators: open
I'm using a free calendar script which produces 3 select menus (or drop downs) for the date using this code:
<script>DateInput('orderdate', true, 'YYYY-MM-DD')</script>
The date that they select in the 3 select menus is saved in the YYYY-MM-DD format. How can I get that variable/data passed on to my hidden input field within the same page/form:
<input name="Date" value="NEED-THE-YYYY-MM-DD-DATE-HERE" type="hidden">
Is there like a print/write function or something else that can grab/copy the date produced from the JS calendar and add it to the hidden input so that when the form submits, the hidden input has the proper date data?
Hope I made sense. Any help would be aprpeciated
I was looking at some scripts that allow you to do this to text boxes with a check box (for example when you copy billing address to shipping address) except that my fields are a hidden input and a select menu and not text boxes. Furthermore, my input names are very bad and have periods in them so I don't know how to get it to work with the javascript code. For example, one of my fields is: air.y.leg1.departLocation
I am not able to change the field names. Does anyone know of a way I could get this to work?
<script type="text/javascript">
function copyThisValue(obj,hidID){
document.getElementById(hidID).value = obj.value;
}
//I just threw this function below in for demo to see the hidden values
//(after you type in the input and make a selection of course
function seeHiddenValues() {
var hidValOne = document.getElementById('copiedStuffOne').value;
var hidValTwo = document.getElementById('copiedStuffTwo').value;
alert(hidValOne+"\n"+hidValTwo);
}
</script>
</head>
<body>
<form action="" name="someForm">
<p><input type="text" size="50" onkeyup="copyThisValue(this,'copiedStuffOne');" />
<select onchange="copyThisValue(this,'copiedStuffTwo');">
<option selected="selected">Choose an option</option>
<option value="someValue">Option one</option>
<option value="someOtherValue">Option two</option>
<option value="anotherValue">Option three</option>
</select>
<input id="copiedStuffOne" type="hidden" />
<input id="copiedStuffTwo" type="hidden" />
<!-- the button below is just for demo -->
<input type="button" value="See The Hidden Values" onclick="seeHiddenValues();" /></p>
</form>
I can use the code as is. I can add my own form fields and get it to return the proper value in the alert box. What I cannot do, is actually write to the hidden form field with the proper value.
The idea with my form is that a donor can choose a preset payment amount via a radio button or enter a custom amount for donating. then I need to pass the selected option's value to the hidden field "chargetotal" which will get passed to the cc processing gateway. I have other forms, but in those cases, I set the chargetotal value by hand.
here is the form.
<form name="donations" action="https://www.staging.yourpay.com/lpcentral/servlet/lppay" method="post">
<input name="chargetotal" id="chargetotal" type="hidden" />
<input type="hidden" name="package" value="Donation">
<label><input type="radio" name="donation" value="150.00" onchange="radio_checker();" onclick="copyThisValue(this,'chargetotal');" /> $150.00</label>
<br />
<label><input type="radio" name="donation" value="250.00" onchange="radio_checker();" onclick="copyThisValue(this,'chargetotal');" /> $250.00</label>
<br />
<label><input type="radio" name="donation" value="500.00" onchange="radio_checker();" onclick="copyThisValue(this,'chargetotal');" /> $500.00</label>
<br />
<input type="radio" name="donation" value="custom" id="custom_amount" onchange="radio_checker();" />
Other:
<input type="text" name="custom_donation" disabled="true" onkeyup="copyThisValue(this,'copiedStuffOne');" />
<br />
<p><input type="submit" value="Continue"></p>
</form>
if I set the button to type="button", etc as in the original post, I can make the alert popup and state the right value. but I need to set it so that the value of chargetotal is passed on when I submit the form. here is the javascript I am using:
<script type="text/javascript" language="javascript">
function copyThisValue(obj,hidID){
document.getElementById(hidID).value = obj.value;
}
function seeHiddenValues() {
var hidValOne = document.getElementById('chargetotal').value;
var hidValTwo = document.getElementById('copiedStuffTwo').value;
alert(hidValOne+"\n"+hidValTwo);
}
function radio_checker() {
if (document.donations.custom_amount.checked) {
document.donations.custom_donation.disabled = false;
document.donations.custom_donation.focus();
}
else {
document.donations.custom_donation.disabled = true;
}
}
</script>
I thought maybe something like this would do it, but I just can't make it work...
<script type="text/javascript" language="javascript">
var hidValOne = document.getElementById('chargetotal').value;
document.donations.chargetotal.value=hidValOne
</script>
there are three other pieces to this that I am also struggling with, and not sure if its better to address all at once or in pieces, so I list them here for reference if for nothing else:
(1) need to check the custom_donation input field and add ".00" to the number if it is missing (formatting)
(2) need to check the custom_donation input field and make sure it is no less than $5.00 (can't accept donations less than $5.00)
(3) add an option for making the donation monthly (check box?), which if checked would add 5 additional hidden fields:
<INPUT name="submode" value="periodic" type="hidden">
<INPUT name="periodicity" value="m1" type="hidden">
<INPUT name="installments" value="12" type="hidden">
<INPUT name="threshold" value="3" type="hidden">
<input type="hidden" name="startdate">
your help and advice is most appreciated.