• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1783
  • Last Modified:

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

0
vishey68
Asked:
vishey68
  • 8
  • 6
  • 5
2 Solutions
 
Geert BormansInformation ArchitectCommented:
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
0
 
Geert BormansInformation ArchitectCommented:
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

0
 
vishey68Author Commented:
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
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
ChristoferDutzCommented:
Well you have programmed it that way ... you call clickRadio with this ... this ist the radio-button instance and you output the value of this object, which is set to "Hello" fixed.
What you would need to do, is to pass a reference to the td-element containing the value you want to output.
0
 
Geert BormansInformation ArchitectCommented:
what you need the, I think is
<input type="radio" name="group3"  value="{wells_ID}" onclick="clickRadio(this)"  />
That is the advantage of XSLT, that you can make the input elements dynamic
0
 
vishey68Author Commented:
I know, but i really do not know how to do it. If you could please give me some idea i can do it
0
 
ChristoferDutzCommented:
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

0
 
ChristoferDutzCommented:
Argl ... try "parentNode" instead of "parent"
0
 
ChristoferDutzCommented:
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]"
0
 
Geert BormansInformation ArchitectCommented:
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
0
 
ChristoferDutzCommented:
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

0
 
ChristoferDutzCommented:
I allways thought the dom navigation functios are the same on all browsers (at least something where they "should" work equally ;-) )
0
 
Geert BormansInformation ArchitectCommented:
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>
0
 
Geert BormansInformation ArchitectCommented:
> 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
0
 
Geert BormansInformation ArchitectCommented:
Ha, I did not see your previous post (24430340)
but I agree, from what I know now, it should be pre cooked
0
 
vishey68Author Commented:
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
0
 
vishey68Author Commented:
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
0
 
vishey68Author Commented:
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.

0
 
Geert BormansInformation ArchitectCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now