User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,640 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,669 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1112 | Replies: 1
Reply
Join Date: Aug 2006
Posts: 23
Reputation: yenyen is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
yenyen yenyen is offline Offline
Newbie Poster

put checked radio ID separated by a delimiter into hidden field

  #1  
Jan 23rd, 2008
<!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>
hi there..i need some help. above is my HTML code from my view source page. i got a list of dynamic radio button wif the radio button name is differnt . in the radio button, when onclick i call two function. for the 2nd fucntion, i need to pass 1 kind of value that is photoid (not the radio button own value) to the function. chkPhoto('3');" . wat i need to do is, when onclick any radio button, it will directly assign the PARAMETER photo id into the text box (hidden field) with the delimeter '.'(dot). but wat i have did is...this will add continous when i click on the radio button. let said, from the code. i have photo id 1,3. first time, i click the radio button, it will asssing the value into the text box. but after that, i click the radio button again, it add the valeu again. wat i wan is it jz will display 1.3 not everytime i click the radio button, it will be like this 1.1.3.3.1.1.3. soli for the poor explaination. hope u all understand..plz help..urgent..thank you.. hope u all can help me check this code..thank you very much
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,851
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: put checked radio ID separated by a delimiter into hidden field

  #2  
Jan 23rd, 2008
> var obj = eval("document.list_photo." + objId);
Don't use eval. It's like using a powerhouse to light a single bulb. The same thing can be done using var obj = document.forms['list_photo'].elements[objId. The same can be said about the other places you have used eval. Read the Javascript FAQ for more details.

> wat i wan is it jz will display 1.3 not everytime i click the radio button
If you are pretty sure that the format will always be x.y (e.g. 1.4), you can search for a dot(.) at the start of the function and if one is present, skip the remaining function. Or you can set a flag as soon as you are done and skip the function if the flag value is true.

var delim = ".";
var oldv = document.getElementById('photo').value;
if(oldv.indexOf(delim) == -1) {
   /* the remaining function goes here */
}
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC