SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with a javascript function

    <TR>
    <TD><INPUT type="radio" value="radio1" name="radio1"></TD>
    <TD>D</TD>
    <TD>C</TD>
    <TD>B</TD>
    <TD>A</TD>
    </TR>

    <TR>
    <TD><INPUT type="radio" value="radio2" name="radio2"></TD>
    <TD>T</TD>
    <TD>K</TD>
    <TD>P</TD>
    <TD>R</TD>
    </TR>

    <INPUT TYPE="button" VALUE="Submit" onclick="getVal()" >

    getVal() should return value of fourth <TD> and print an alert .

    How to write getVal() function ?



    Example:

    if user chooses "radio1" . it prints 'B'
    if user chooses "radio2" . it prints 'P'

  2. #2
    SitePoint Wizard Blake Tallos's Avatar
    Join Date
    Jun 2008
    Location
    Cuyahoga Falls, Ohio.
    Posts
    1,511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by windowsxp View Post
    <TR>
    <TD><INPUT type="radio" value="radio1" name="radio1"></TD>
    <TD>D</TD>
    <TD>C</TD>
    <TD>B</TD>
    <TD>A</TD>
    </TR>

    <TR>
    <TD><INPUT type="radio" value="radio2" name="radio2"></TD>
    <TD>T</TD>
    <TD>K</TD>
    <TD>P</TD>
    <TD>R</TD>
    </TR>

    <INPUT TYPE="button" VALUE="Submit" onclick="getVal()" >

    getVal() should return value of fourth <TD> and print an alert .

    How to write getVal() function ?



    Example:

    if user chooses "radio1" . it prints 'B'
    if user chooses "radio2" . it prints 'P'


    You can do something like this -

    Code JavaScript:
    function InputField(){
        var myInput = document.getElementById('myForm');
        if(myInput.value!="")
             alert("you submitted" + myInput.value)
          else
             alert('Please enter form correctly')
    }
    Code HTML4Strict:
    <input type="" id="MyInput">
    <input type="button" onclick="InputField()" value="form">
    Blake Tallos - Software Engineer for Sanctuary
    Software Studio, Inc. C# - Fanatic!
    http://www.sancsoft.com/


  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BlakeAnthony View Post
    You can do something like this -

    Code JavaScript:
    function InputField(){
        var myInput = document.getElementById('myForm');
        if(myInput.value!="")
             alert("you submitted" + myInput.value)
          else
             alert('Please enter form correctly')
    }
    Code HTML4Strict:
    <input type="" id="MyInput">
    <input type="button" onclick="InputField()" value="form">

    there were no radio in your comments.

    I told,

    Example:

    if user chooses "radio1" . it prints 'B'
    if user chooses "radio2" . it prints 'P'

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Notice how clicking on one of the radio buttons doesn't uncheck the other radio button? For a radio button to be part of a group with other radio buttons, they need to share a common name. If this isn't the desired behavior, then you should probably be using checkboxes.

    Have a read
    http://javascript.about.com/library/blradio1.htm

    Try to get the function to just alert the value of the appropriate radio. Once you have that, I'll help you print out the corresponding td text.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •