SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio button alert message doesn't appear???

    I am wondering if someone could please tell me why the following code doesn't work?

    Code JavaScript:
    function validate() {
    if (document.forms.weborderForm.domainradiogroup.checked == true) {
    	alert("testing");
    }
    }

    Code:
    <input type="radio" name="domainradiogroup" id="domainradiogroup" value="No" onclick="javascript:validate();" />
    Thanks in advance.

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As you've set an id on the input, use the document.getElementById method instead, it would be alot easier
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have made the changes to my code Markdidj however it still isn't working. Here is the updated code:
    Code JavaScript:
    function validate() {
    var a = document.getElementById('domainradiogroup').value;
    if (a == 'No') {
    	alert("message here");
    }
    }

    Code:
    <input type="radio" name="domainradiogroup" id="domainradiogroup" value="No" onclick="javascript:validate();" />

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    an onclick calls javascript, so "javascript:" isn't needed. That's only needed for href's
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use onclick="validate(this)"

    and
    Code:
    function validate(obj){
       if(obj.value=="No") alert("message here");
    }
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  6. #6
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is now solved thanks to Markdidj. The above code worked for me.


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
  •