开发者

Script for each of 100+ forms on my site, condensed into one

开发者 https://www.devze.com 2023-02-10 16:15 出处:网络
I have a page with many forms that will send a user to a PayPal page with some preset values. Depending on a value they change, the form will concatenate those into the final \"item_name\" hidden inpu

I have a page with many forms that will send a user to a PayPal page with some preset values. Depending on a value they change, the form will concatenate those into the final "item_name" hidden input.

For each form I have a php page set up that puts this form and html together for me, and automatically enters a unique number after every instance of "action". So the function becomes combAction2() and the form name "action2", etc. etc.

I can't figure out a way to have only one script that changes the "form number" and javascript function per form changed. Any ideas to make just one script? Or way to make the script more efficient if I do indeed need to have one per item? Thanks.

<script type="text/javascr开发者_如何学JAVAipt">
        function combAction1()
        {
        var action1person = document.forms['action1'].action1person.value;
        var action1action = document.forms['action1'].action1action.value;
        document.forms['action1'].item_name.value = action1person + ", " + action1action;
        }
</script>
<form name="action1" action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post" onSubmit="combAction1()">
       <input type="hidden" name="cmd" value="_xclick">
       <input type="hidden" name="paymentaction" value="authorization">
       <input type="hidden" name="business" value="information@ramatico.com">
       <input type="hidden" name="currency_code" value="USD">
       <input name="amount" value="5.00" type="hidden">
       <input name="action1action" type="hidden" value="Action 1 text">
       <select name="action1person" OnChange="combAction1()">
            <option value="Person 1">Person 1</option>
            <option value="Person 2">Person 2</option> 
            <option value="Person 3">Person 3</option> 
            <option value="Person 4">Person 4</option> 
       </select>
       <input type="hidden" id="item_name" name="item_name" value="item_name">
       <a href="#" onclick="document['action1'].submit()">Submit</a>
</form>


<script type="text/javascript">
        function combAction1(frm)
        {
            var action1person = frm.action1person.value;
            var action1action = frm.action1action.value;
            frm.item_name.value = action1person + ", " + action1action;
        }
</script>

<form name="action1" action="https://www.paypal.com/cgi-bin/webscr" onsubmit="combAction1(this.form);">
..
..
<input type="submit" />
</form>

If it is just one form on the page and you think that will never change, you can just use the index

document.forms[0].fieldName
0

精彩评论

暂无评论...
验证码 换一张
取 消