SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question put checked radio ID separated by a specified delimiter

    halo there..need some help here..hope u all can help ya.
    i got a list of radiobutton, with differnt name.
    when i click on the radio button, it willpass the 'ID' into the JS function, how can i get the CHEKED radio ID and put in the hidden field first? i wan to put the all checked radio ID separated by a specified delimiter, such as in this format--> 1.2.3.4.5.6 with the delimiter '.'. can some one plz help me? thanx. bewlow is my html code :
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
        <title>Untitled Page</title>
    </head>
    
    <script language ="javascript">
    
    function chkRadio()
    
    {
    
    
    
        column =document.list_photo.hidCounter.value;
    
        var total = 0;
    
        var file =0;
    
    
    
        for(var i=1; i<=column; i++)
    
        {
    
            var objId = "chkBuy" + i;
    
            var obj = eval("document.list_photo." + objId);
    
            document.list_photo.totalcredit.value = obj.length;
    
          for(var j=0; j<obj.length; j++)
    
          {
    
            if(obj[j].checked && obj[j].value != 0)
    
            {
    
            total += eval(obj[j].value);
    
            file++;
    
            }
    
          }
    
        }
    
        document.list_photo.total_file.value =file;
    
        document.getElementById('totalfile').innerHTML =file;
    
        document.getElementById('creditcost').innerHTML =total;
    
    }
    
    
    
    function chkPhoto(photoid)
    
    {
    
           delim ='.';
    
           v =photoid;
    
           v=v+delim;
    
        var oldv=document.getElementById('photo').value;
    
        document.getElementById('photo').value=oldv+v;
    
    }
    
    
    
    function chkValue()
    
    {
    
        column =document.list_photo.hidCounter.value;
    
        var checked =false;
    
        if(document.list_photo.chkAgree.checked ==false)
    
        {
    
            alert("Please agree To terms");
    
            return false;
    
        }
    
    
    
        if(document.list_photo.total_file.value =="")
    
        {
    
                alert("Please select the images you wish to download.");
    
                return false;
    
        }
    
            document.list_photo.hidSubmit.value ="Submit";
    
            boxid =document.list_photo.hidboxid.value;
    
            document.list_photo.action ="lightbox_download.asp?boxid="+ boxid ;
    
            document.list_photo.submit();
    
    }
    
    
    
    </script>
    
    <body>
    
    <a href="list_lightbox.asp">List lightbox</a><br /><br />
    
    <form name="list_photo" id="f1" method="post">
    
    <table border="1">
    
    
    
        <tr>
    
            <td valign="top">IMAGE DISPLAY HERE</td>
    
            <td  valign="top"><a href ="view_photo.asp?photoid=1">dog</a><BR /> alice</td>
    
            <td>
    
    
    
                <table>
    
    
    
                    <tr>
    
                    <td>XSmall&nbsp; - 100 x 100 px @ 72 Dpi  </td>
    
                    <td>- 1Credit</td>
    
                    <td><input type="Radio" name="chkBuy1" value="1" onClick="chkRadio();chkPhoto('1');" /></td>
    
                    </tr>
    
    
    
                    <tr>
    
                    <td>Small&nbsp; - 200 x 280 px @ 72 Dpi  </td>
    
                    <td>- 3Credits</td>
    
                    <td><input type="Radio" name="chkBuy1" value="3" onClick="chkRadio();chkPhoto('1');" /></td>
    
                    </tr>
    
    
    
                    <tr>
    
                    <td>Medium&nbsp; - 500 x 600 px @ 300 Dpi  </td>
    
                    <td>- 5Credits</td>
    
                    <td><input type="Radio" name="chkBuy1" value="5" onClick="chkRadio();chkPhoto('1');" /></td>
    
                    </tr>
    
    
    
                    <tr>
    
                        <td colspan="2" align="right">Skip This image file</td>
    
                        <td>
    
                        <input type="Radio" name="chkBuy1" value="0" onClick="chkRadio(this.value,'1')"  checked />
    
                        <input type="text" name="hiddX" value="1" size="5"/>
    
                        <input type="hidden" name="totalrecord1" value="" size="5"/>
    
                        </td>
    
                    </tr>
    
    
    
                </table>
    
              </td>
    
        </tr>
    
        <tr>
    
            <td valign="top">IMAGE DISPLAY HERE</td>
    
            <td  valign="top"><a href ="view_photo.asp?photoid=3">cat</a><BR /> lenny</td>
    
            <td>
    
    
    
                <table>
    
    
    
                    <tr>
    
                    <td>Small&nbsp; - 200 x 250 px @ 72 Dpi  </td>
    
                    <td>- 3Credits</td>
    
                    <td><input type="Radio" name="chkBuy2" value="3" onClick="chkRadio();chkPhoto('3');" /></td>
    
                    </tr>
    
    
    
                    <tr>
    
                    <td>XSmall&nbsp; - 250 x 250 px @ 72 Dpi  </td>
    
                    <td>- 1Credit</td>
    
                    <td><input type="Radio" name="chkBuy2" value="1" onClick="chkRadio();chkPhoto('3');" /></td>
    
                    </tr>
    
    
    
                    <tr>
    
                        <td colspan="2" align="right">Skip This image file</td>
    
                        <td>
    
                        <input type="Radio" name="chkBuy2" value="0" onClick="chkRadio(this.value,'2')"  checked />
    
                        <input type="text" name="hiddX" value="2" size="5"/>
    
                        <input type="hidden" name="totalrecord2" value="" size="5"/>
    
                        </td>
    
                    </tr>
    
    
    
                </table>
    
              </td>
    
        </tr>
    
    
    
        <tr>
    
            <td colspan="3">
    
            <input type="text" name="photo" id="inputs"  />
            </td>
        </tr>
     </table>
    </form>
    </body>
    </html>
    when i onclick the radio button, i call two function. the radio buttons value is loop from the Db so it has differnet name for every row. when i clicked on the radio button, one of the calling fucntion is chkPhoto('1')--> it will pass the photoid to the fucntion. if let say got three photo or more, how can i pass the value(assign it into the hidden text field name 'photo'? i would like to assign it in this format --> 1.2.3 with the delimiter join on the checked photo value.plz help
    Last edited by purple83; Jan 23, 2008 at 03:26.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Here's a quick something I ran up that you should be able to make good use of.

    Code HTML4Strict:
    <form action="submit.php" onsubmit="return process(event);">
    ...

    Code Javascript:
    function process(e) {
    	var targ, elem, values, i;
        e = e || window.event;
    	targ = e.target || e.srcElement;
    	values = [];
    	for (i = 0; i < targ.elements.length; i++) {
    		elem = targ.elements[i];
    		if (elem.nodeName === 'INPUT') {
    			if (elem.getAttribute('type') === 'radio') {
    				if (elem.checked === true) {
    					values.push(elem.getAttribute('value'));
    				}
    			}
    		}
    	}
    	values = values.join('.');
    	return false;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    heloo there, can help me based on my code? thanx

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Work it in to your own code and if you can't get it to work, we'll help you work through any issues.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there..yes.i have try. but i got some issues like everytime i clicked on the radio button it will add and add..unlimited..plz help.thank you.

    p/s : i oeldi post my code above..plz help.thank you


Bookmarks

Posting Permissions

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