Solved

How to get value on click of a radio button

Posted on 2009-05-20
19
1,705 Views
Last Modified: 2013-11-19
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
Comment
Question by:vishey68
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 5
19 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430163
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430182
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
 

Author Comment

by:vishey68
ID: 24430215
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 200 total points
ID: 24430246
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
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 300 total points
ID: 24430266
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
 

Author Comment

by:vishey68
ID: 24430274
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24430282
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24430288
Argl ... try "parentNode" instead of "parent"
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24430301
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430335
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24430340
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24430345
I allways thought the dom navigation functios are the same on all browsers (at least something where they "should" work equally ;-) )
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430346
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430358
> 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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430366
Ha, I did not see your previous post (24430340)
but I agree, from what I know now, it should be pre cooked
0
 

Author Comment

by:vishey68
ID: 24430591
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
 

Author Closing Comment

by:vishey68
ID: 31583437
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
 

Author Comment

by:vishey68
ID: 24430639
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24430920
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question