www.webdeveloper.com
Results 1 to 6 of 6

Thread: radio button

  1. #1
    Join Date
    Feb 2004
    Posts
    92

    radio button

    I am trying to use Ajax to pass the form selections to the next page without the page actually moving...

    here is how I am doing it:
    HTML
    HTML Code:
    <form name="formname">
    <input type="radio" name="bid" value="123">
    <input type="radio" name="bid" value="234">
    <input type="radio" name="bid" value="345">
    <a href="javascript:void(0)" onclick="sendform('formname','bid',document.formname.bid.value);">Send Data</a>
    that does not work, so how do I send the radio button value since it has more than one place, how does it know which one to send?
    I tried this:
    HTML Code:
    <form name="formname">
    <input type="radio" name="bid" value="123">
    <input type="radio" name="bid" value="234">
    <input type="radio" name="bid" value="345">
    <a href="javascript:void(0)" onclick="sendform('formname','bid',document.getElementByName('bid').selectedIndex);">Send Data</a>
    That does not work either.

    any clues?

    Thanks,
    Richard

  2. #2
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    Depends what "sendform" is doing. Can you show that code?

  3. #3
    Join Date
    Feb 2004
    Posts
    92
    Quote Originally Posted by crh3675 View Post
    Depends what "sendform" is doing. Can you show that code?
    yes:

    Code:
    function sendform(form,do,dov) {
      request = createRequest();
      if(request == null) {
        alert("Unable to Create Request");
        return;
      }
      var nocache = new Date();
      var url = "index.cgi?pg=processpage&"+do+"="+dov + "&stopIEcache="+ nocache;
      request.open("GET",url,true);
      request.onreadystatechange = spimg;
      request.send(null);
    }

  4. #4
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    Since you aren't letting the standard browser handle the radio element, you will have to accommodate for that. If you were using a JS framework like Prototype or jQuery, it would be easy. In your case you would need something like:

    Code:
    function getRadioValue(name)
    {
        var found = '';
        var all =  document.getElementsByTagName('input');
        for(i=0;i<all.length;i++)
        {
            if(all[i].getAttribute('name') == name && all[i].checked)
            {
                found = all[i].value;
                break;
            }
        }
        return found;
    }
    and


    Code:
    <a href="javascript:void(0)" onclick="sendform('formname','bid', getRadioValue('bid'));">Send Data</a>

  5. #5
    Join Date
    Feb 2004
    Posts
    92
    What is the ('input') do I need to name that something, or do I leave it ('input') ?

    Thanks
    Last edited by ukndoit; 11-22-2009 at 07:16 AM.

  6. #6
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    "input"? Is exactly what the code says, a tag name.

    <input

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles