View Full Version : Forms & Combining Fields...
IronMonkey
04-26-2003, 11:18 PM
Hi,
I'm in the process of setting up a site which offers a fixed price service, and thinking of going with the payment service provider Worldpay.
For me to provide the service, I need customers to give me three specific pieces of data.
However, I can't pass that data onto Worldpay as three fields! They first need to, somehow, be combined into one field!
So this is how far I have got:
I have a form with three fields (eg 'field1', 'field2', 'field3'). Once a customer completes the form and clicks submit, the three fields get validated.
Now, this is what I'm stuck on:
1) What I then want is those three fields to be summarised into a new field (eg 'summarised_field').
2) Then finally I want the form with the new field ('summarised_field') to be posted to the Worldpay payment page (but not with the original three fields).
Anyone know how to do this?
Thanks.
boywonder
04-26-2003, 11:43 PM
You can just add a hidden field to your form called
'summarised_field'
in your validation script which I assume is called onsubmit you say the text fields get validated... during that process add each one to the hidden field's value using += as in
document.formname.summarised_field.value += some text field's value
or if there's supposed to be a separator in there you can add that in as well
As far as preventing some fields from not being sent... set disabled = true for them at the end of the function. (I am not sure however if certain browsers might send them anyway - I know IE will not)
does that help?
Algorithm
04-26-2003, 11:47 PM
Use two forms. One with the three visible inputs, and another with a hidden input for submission to your script.
For the visible form (replace doValidate with your validation function):
<form name="input" action="javascript:void(doValidate())">
Then, once your validation is complete, you can paste the result string into your second form and call its submit() method.
IronMonkey
04-27-2003, 12:15 AM
Thanks for the replies guys. I'm looking into what you two have advised.
I think I've read somewhere that if you put 'id' instead of 'name' ( i.e <input id=field1> ), then those fields don't get submitted, but they can still be used for JavaScript! Do you know if this's true?
liorean
04-27-2003, 12:35 AM
Name attribute (!="") is needed for a field to be submitted, yes. It's also required on all input elements except reset and submit. (According to a comment in the DTD. There is no way for the DTD to specify that they are required depending on an attribute value, so they aren't validated for that.)
According to the DOM the document.forms and form.elements collection takes either an index or an id or name value. However, traditionally name attribute only was used for that, and browsers needn't have changed to the DOM way. document.getElementById will always apply to all elements with an id, though.
IronMonkey
04-27-2003, 09:19 PM
Cheers for that Liorean, but I don't know if I fully understand it!
Someone's done the following for me & it works. It's basically a combination of Algorithm & Boywonder's suggestions:
<script type="text/javascript" language="JavaScript">
function summarize() {
var strSummary = ' ';
strSummary += document.form1.input1.value + document.form1.input2.value + document.form1.input3.value;
document.form2.summary.value = strSummary; document.form2.submit(); }
</script>
<form name="form1">
<input name="input1" type="text" value="" /><br />
<input name="input2" type="text" value="" /><br />
<input name="input3" type="text" value="" /><br />
</form>
<form name="form2" action="about :blank" onsubmit="summarize()">
<input name="summary" type="hidden" value="" />
<input name="btnSubmit" type="submit" value="Submit" />
</form>
I've edited it to include validation, separators...
One more thing, I don't suppose any of you know if the code above is compatible with Netscape...?
Everyone, thanks for your help, it's appreciated! :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.