Solved

How to get value on click of a radio button

Posted on 2009-05-20
19
1,677 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now