option value not working

Hi experts,

Here is a small code. the problem is that:

window.document.getElementById('sitesearch').value

do not return any value

Thanks


      <table>
            <tr>
                  <td><a href="http://www.google.com"><img src="http://www.google.com/logos/Logo_40wht.gif" border="0"

alt="Google" align="middle" /></a></td><td><input id="txtGoogleSearch" name="txtGoogleSearch" maxlength="255" size="40"

type="text" onkeypress="if (window.event.keyCode==13) googleSearch();" /><span style="width:10px;"></span><input

value="Google Search" onclick="googleSearch();" type="button" /><span style="width:20px;"></span></td>
            </tr>
      </table>
      <tr>
<td>
<input type="radio" id="sitesearch" name="sitesearch" value="" checked="checked"></input>
<font size="-1" color="#000000">Web</font>
</td>
<td>
<input type="radio"  id="sitesearch" name="sitesearch" value="a7fr.com"></input>
<font size="-1" color="#000000">a7fr.com</font>
</td>
      <script>
            function googleSearch(){  var searchURL;  

searchURL='http://www.google.com/custom?domains=a7fr.com&sa=Rechercher&client=pub-2629112546167182&forid=1&ie=ISO-8859-1&oe=I

SO-8859-1&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3

A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A24%3BLW%3A100%3BL%3Ahttp%3A%2F%2Fa7fr.com%2Fimages%

2Fbanner250w60h.gif%3BS%3Ahttp%3A%2F%2Fwww.a7fr.com%3BLP%3A1%3BFORID%3A1%3B&hl=fr&sitesearch=' +

window.document.getElementById('sitesearch').value + '&q=';    searchURL=searchURL +

window.document.getElementById('txtGoogleSearch').value; window.open(searchURL, '_blank');}
      </script>
cabouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
Both radio controls are different as far as javascript is concerned. So they are accessed as window.document.getElementById('sitesearch')[0].value and window.document.getElementById('sitesearch')[1].value. Use window.document.getElementById('sitesearch')[0].checked to see if it is checked. So in your code

Change

window.document.getElementById('sitesearch').value

to

(window.document.getElementById('sitesearch')[0].checked ? window.document.getElementById('sitesearch')[0].value : window.document.getElementById('sitesearch')[1].value)
cabouAuthor Commented:
Here what I did but it is not working.

      <table>
            <tr>
                  <td><a href="http://www.google.com"><img src="http://www.google.com/logos/Logo_40wht.gif" border="0"

alt="Google" align="middle" /></a></td><td><input id="txtGoogleSearch" name="txtGoogleSearch" maxlength="255" size="40"

type="text" onkeypress="if (window.event.keyCode==13) googleSearch();" /><span style="width:10px;"></span><input

value="Google Search" onclick="googleSearch();" type="button" /><span style="width:20px;"></span></td>
            </tr>
      </table>
      <tr>
<td>
<input type="radio" id="sitesearch" name="sitesearch" value="" checked="checked"></input>
<font size="-1" color="#000000">Web</font>
</td>
<td>
<input type="radio"  id="sitesearch" name="sitesearch" value="a7fr.com"></input>
<font size="-1" color="#000000">a7fr.com</font>
</td>
      <script>
            function googleSearch(){  var searchURL;  

searchURL='http://www.google.com/custom?domains=a7fr.com&sa=Rechercher&client=pub-2629112546167182&forid=1&ie=ISO-8859-1&oe=I

SO-8859-1&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3

A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A24%3BLW%3A100%3BL%3Ahttp%3A%2F%2Fa7fr.com%2Fimages%

2Fbanner250w60h.gif%3BS%3Ahttp%3A%2F%2Fwww.a7fr.com%3BLP%3A1%3BFORID%3A1%3B&hl=fr&sitesearch=' +

(window.document.getElementById('sitesearch')[0].checked ? window.document.getElementById('sitesearch')[0].value :

window.document.getElementById('sitesearch')[1].value) + '&q=';    searchURL=searchURL +

window.document.getElementById('txtGoogleSearch').value; window.open(searchURL, '_blank');}
      </script>
Cem TürkSenior Software EngineerCommented:
<html>
<head>
     <script type="text/javascript">
function googleSearch() {  
var searchURL;  
searchURL='http://www.google.com/custom?domains=a7fr.com&sa=Rechercher&client=pub-2629112546167182&forid=1&ie=ISO-8859-1&oe=I';
searchURL+='SO-8859-1&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3';
searchURL+='A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A24%3BLW%3A100%3BL%3Ahttp%3A%2F%2Fa7fr.com%2Fimages%';
searchURL+='2Fbanner250w60h.gif%3BS%3Ahttp%3A%2F%2Fwww.a7fr.com%3BLP%3A1%3BFORID%3A1%3B&hl=fr&sitesearch=';

var radios=document.getElementsByName('sitesearch');

if(radios[0].checked==true) {

searchURL= searchURL + radios[0].value;
 }
else {

searchURL= searchURL + radios[1].value;
}  

 searchURL=searchURL +  '&q=' +window.document.getElementById('txtGoogleSearch').value;

window.open(searchURL, '_blank');

}
     </script>
</head><body>
     <table>
          <tr>
               <td><a href="http://www.google.com"><img src="http://www.google.com/logos/Logo_40wht.gif" border="0"

alt="Google" align="middle" /></a></td><td><input id="txtGoogleSearch" name="txtGoogleSearch" maxlength="255" size="40"

type="text" onkeypress="if (window.event.keyCode==13) googleSearch();" /><span style="width:10px;"></span><input

value="Google Search" onclick="googleSearch();" type="button" /><span style="width:20px;"></span></td>
          </tr>
     </table>
     <tr>
<td>
<input type="radio" id="sitesearch" name="sitesearch" value="" checked="checked"></input>
<font size="-1" color="#000000">Web</font>
</td>
<td>
<input type="radio"  id="sitesearch" name="sitesearch" value="a7fr.com"></input>
<font size="-1" color="#000000">a7fr.com</font>
</td></body></html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.