SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClick of textarea, autochange radio option

    I have a form with two radio options and a text area. The first option if highlighted by default. If the user clicks or tabs (onfocus) to the text area, I want the second radio option to automatically be highlighted.

    eg. two radio's named "options", values "all" and "mine" and a textarea named "emails". "all" is already highlighted. When I click on "emails", I want "mine" to be highlighted automatically.

    <input type="radio" name="options" value="all" checked>
    <input type="radio" name="options" value="mine">
    <textarea name="emails" cols="50" rows="10">
    content</textarea>

    Any help or ideas would be great.

    Cheers
    Si

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if there's a better way of going about this, but this code seems to be working for me:

    Code:
    function checkSecondOption() {
    	for(i = 0; i < document.forms[0].elements.length; i++) {
    		if (document.forms[0].elements[i].value == "Option2")
    			document.forms[0].elements[i].click();
    	}
    }
    -----------------------------------------------------------
    
    <FORM>
    <INPUT TYPE="RADIO" NAME="Option" VALUE="Option1" CHECKED>Option 1<BR>
    <INPUT TYPE="RADIO" NAME="Option" VALUE="Option2">Option 2<BR>
    <BR>
    <TEXTAREA NAME="Content" ROWS="5" COLS="50" onFocus="checkSecondOption()"></TEXTAREA>
    </FORM>
    Hope it helps!
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.


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
  •