Link to home
Start Free TrialLog in
Avatar of vishey68
vishey68

asked on

How to get value on click of a radio button

I have a very basic knowledge of XML/XSLT. I have defined rows of data having radio button. I would like to know how do we give a particular column vale on click of a radio button. I have an xml which is an input to the data. I have attached the code below. Thanks for having a look
<xsl:for-each select="Accounts/Account[wells_ACCT_TYPE_CD='C']">
      <tr>
        <td>    
	        
              	<input type="radio" name="group3"  value="Hello" onclick="clickRadio(this)"  />
		
	</td>	
	<td><xsl:value-of select="wells_ID"/></td>
        <td><xsl:value-of select="HI_LVL_PRNT_ID"/></td>
        <td><xsl:value-of select="CORP_TOT_PROG_CANC_DT"/></td>
        <td><xsl:value-of select="CORP_NM"/></td>
        <td><xsl:value-of select="CORP_DEROG_TOT_BAL_AMT"/></td>
        
      </tr>
      </xsl:for-each>
 
At present  it is getting a value of hello on click of any row. I would like to give the particular row wells_id in this javascript
 
function clickRadio(te)
  {
  alert(te.value);
  }

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

For me that works,
make sure that in the resulting html the javascript is "accessible" from teh radio button...
so, put it in a script tag in the head section of the html, that is the best
with "it works", I mean that I tested it in three browsers (opera, firefox and IE)
with this html


make sure that the xslt generates something like that, so test a static transform first

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
 <script language="javascript">
function clickRadio(te)
  {
  alert(te.value);
  }
</script>
</head>
<body>
             	<input type="radio" name="group3"  value="Hello" onclick="clickRadio(this)"  >Test</input>

Open in new window

Avatar of vishey68
vishey68

ASKER

I did not make myself clear, at present on click of any radio button of any row, the value that is being passed is hello the hard coded value. I would like to get the value from XML corresponding to the row. If the first radio button is clicked then the value of wells id from the ist data in xml should be sent
SOLUTION
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I know, but i really do not know how to do it. If you could please give me some idea i can do it
Try the following code instead. The idea is to pass the row to the function instead of the radiobutton and to output the content of the second field to the output. I have to admit, that I haven't tested it, so you might have to fine-tune a little ... but maybe it gives you the idea.
<xsl:for-each select="Accounts/Account[wells_ACCT_TYPE_CD='C']">
      <tr>
        <td>    
            <!-- pass the row containing the radio button to clickRadio -->
            <input type="radio" name="group3"  value="Hello" onclick="clickRadio(this.parent.parent)"/>
	</td>	
        <td><xsl:value-of select="wells_ID"/></td>
        <td><xsl:value-of select="HI_LVL_PRNT_ID"/></td>
        <td><xsl:value-of select="CORP_TOT_PROG_CANC_DT"/></td>
        <td><xsl:value-of select="CORP_NM"/></td>
        <td><xsl:value-of select="CORP_DEROG_TOT_BAL_AMT"/></td>
        
      </tr>
      </xsl:for-each>
 
At present  it is getting a value of hello on click of any row. I would like to give the particular row wells_id in this javascript
 
function clickRadio(row)
  {
  // Make alert output the content of the second td of that field. (Index 1 = field 2)
  alert(row.td[1].value);
  }

Open in new window

Argl ... try "parentNode" instead of "parent"
And if "row.tr[1]" doesn't work ... try "childNodes[1]" but I think this could be a little problematic as textNodes count here too ... so you might have to test a little with "childNodes[2]" or "childNodes[3]"
well, the childNodes will not correctly work the same in all browsers I believe,
but I am not sure that he needs DOM tree walking that much,
all should be pre-cooked in teh XSLT, if references realy are needed, I recommend using IDs

but then I would like to see the XML and the XSLT so far, and maybe some detailed requirements
I think you are right, that the following XSL should do the  trick:
<xsl:for-each select="Accounts/Account[wells_ACCT_TYPE_CD='C']">
      <tr>
        <td>    
            <!-- pass the row containing the radio button to clickRadio -->
            <input type="radio" name="group3"  value="{wells_ID}" onclick="clickRadio(this.parent.parent)"/>
	</td>	
        <td><xsl:value-of select="wells_ID"/></td>
        <td><xsl:value-of select="HI_LVL_PRNT_ID"/></td>
        <td><xsl:value-of select="CORP_TOT_PROG_CANC_DT"/></td>
        <td><xsl:value-of select="CORP_NM"/></td>
        <td><xsl:value-of select="CORP_DEROG_TOT_BAL_AMT"/></td>
        
      </tr>
      </xsl:for-each>

Open in new window

I allways thought the dom navigation functios are the same on all browsers (at least something where they "should" work equally ;-) )
If I read all of this well, I still think the solution is

<xsl:for-each select="Accounts/Account[wells_ACCT_TYPE_CD='C']">
      <tr>
        <td>    
              
                    <input type="radio" name="group3"  value="{wells_ID}" onclick="clickRadio(this)"  />
            
      </td>      
      <td><xsl:value-of select="wells_ID"/></td>
> I allways thought the dom navigation functios are the same on all browsers (at least something where they "should" work equally ;-) )

well, I am not 100% sure for HTML, I know that they don't for XML,
since all browsers are counting white-space nodes and IE is not
that is why I stay very much away from counting
Ha, I did not see your previous post (24430340)
but I agree, from what I know now, it should be pre cooked
It works, according to me for whatever it is worth both of you r geniuses. Please tell me , as i am a beg which books gives me the concepts. This will help newbies like us.

Thanks a Lot
Both of u r geniuses. Please tell me which book i need to refer to get these concepts as i am new comer esp the dynamic part of xsl
I have one open question also with the same topic . Can u please have a look at it. The solution already given cannot be implemented as i can not download sariisa for my project.

Please make comments about that other quastion in the other question as well.
I see I have 4 open comments from myself without any feedback from you...
so this feedback does not belong here, but there