Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Location
    upper midwest
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile can i retun the value of chck boxes in a hidden input?

    Is it possialbe to use 20 checkboxes (1 to 20) and 10 radio bottons (1 to 10) to generate the value for "item_name" for a Single Item Purchase with PayPal when they use (<input type="hidden" name="item_name" value="">)? I want to click on 5 of the 20 checkboxes and 1 radio button and send the value in the (<input type="hidden" name="item_name" value="">). I am useing javascript to limt the to five choices
    <script language="javascript">

    function KeepCount() {
    var NewCount = 0
    if (document.item1.A.checked)
    {NewCount = NewCount + 1}
    if (document.item1.B.checked)
    {NewCount = NewCount + 1}
    if (document.item1.C.checked)
    {NewCount = NewCount + 1}
    if (document.item1.D.checked)
    {NewCount = NewCount + 1}.....
    witch workes well. I use a plain radio button<input type="radio" name="item2" value="1">. I want to add the value if item1(witch should be five letters) and the radio button selection and send that as a value for the (<input type="hidden" name="item_name" value="">) Can this be done or am I crazy???? Any help would be wounderful.
    Last edited by gogotina; 04-03-2003 at 06:18 AM.

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this should work...im stillworking on some added functionality but this should be good enough for a while:

    [EDIT: lol, this is quite a project...loop da loop!!...i'll update this as i make it better]

    Code:
    <html>
    <head>
    <title>PayPal</title>
    <script type="text/jav&#97;script">
    <!--;
    
    msg = Object;
    msg['item1'] = "Please select 5 checkbox options"
    
    
    function getValues(f){
    var plHolder,i=0,j,cnt, newItem='';
    f=document.frmChk;
    
    	while(plHolder=f.elements[i++]){
        	if(plHolder.type=='checkbox' || plHolder.type=='radio'){
              	if(plHolder.checked){
                        cnt=[plHolder.value];
                	var j = 0;
              	while(plHolder=cnt[j++])
    		          newItem = newItem + plHolder;
    			}                                                                      
    		}
                                    
    	}
    
        var len = newItem.length
    
        if(len != 6){
             alert(msg['item1'] + "\nYou have selected " + (len - 1));
             f.item1[0].focus();
             return false;
        } else {
    	document.frmSub.item_name.value=newItem
    	return true;
        }
    }
    
    
    //-->
    </script>
    </head>
    <body>
    <form name="frmChk">
    
    <p>
    Please select 5 items from Group One and 1 item from Group Two
    </p>
    <p>
    <strong>Group One</strong>
    </p>
    <INPUT type="checkbox" name="item1" value="A" />A
    <INPUT type="checkbox" name="item1" value="B" />B
    <INPUT type="checkbox" name="item1" value="C" />C
    <INPUT type="checkbox" name="item1" value="D" />D
    <INPUT type="checkbox" name="item1" value="E" />E
    <br />
    <INPUT type="checkbox" name="item1" value="F" />F
    <INPUT type="checkbox" name="item1" value="G" />G
    <INPUT type="checkbox" name="item1" value="H" />H
    <INPUT type="checkbox" name="item1" value="I" />I
    <INPUT type="checkbox" name="item1" value="J" />J
    <br />
    <INPUT type="checkbox" name="item1" value="K" />K
    <INPUT type="checkbox" name="item1" value="L" />L
    <INPUT type="checkbox" name="item1" value="M" />M
    <INPUT type="checkbox" name="item1" value="N" />N
    <INPUT type="checkbox" name="item1" value="O" />O
    <br />
    <INPUT type="checkbox" name="item1" value="P" />P
    <INPUT type="checkbox" name="item1" value="Q" />Q
    <INPUT type="checkbox" name="item1" value="R" />R
    <INPUT type="checkbox" name="item1" value="S" />S
    <INPUT type="checkbox" name="item1" value="T" />T
    <br />
    <p>
    <strong>Group Two</strong>
    </p>
    <INPUT type="radio" name="item2" value="1" checked="checked" />1
    <INPUT type="radio" name="item2" value="2" />2
    <INPUT type="radio" name="item2" value="3" />3
    <INPUT type="radio" name="item2" value="4" />4
    <INPUT type="radio" name="item2" value="5" />5
    <p>
    </form>
    
    <form name="frmSub" action="jav&#97;script: alert('Success!' + '\nHidden Value = ' + document.frmSub.item_name.value)" method="post" onsubmit="return getValues(this)" 
    <strong>Submission</strong>
    </p>
    <input type="hidden" name="item_name" value=""/>
    <input type="submit" value="Submit" />
    <input type="reset" value="reset" />
    
    </FORM>
    
    </body>
    </html>
    Change the form action to your own. Comments on improvement are more than welcome.
    Last edited by HairyTeeth; 04-14-2003 at 10:28 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •