p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   display value of selected radio in the textbox (http://p2p.wrox.com/showthread.php?t=8835)

hosefo81 February 1st, 2004 02:21 AM

display value of selected radio in the textbox
i want the value of the selected radio button to be displayed on the textboxt.
below are my code and there is an error.
i believe it is in the function1().Please correct my code.

    <title>Search Employee Data</title>
<script language="javascript">
function function1()
    document.searchempform.text1.value =document.searchempform.search_emptype[document.searchempform.search_emptype.selectedInde x].value

</head onload="document.searchempform.reset()">

<form name="searchempform">

<b>How do you want to search? </b><br>
<input type="radio" name="search_emptype" value="searchempid" onclick="function1()">Search by Employee ID<br>
<input type="radio" name="search_emptype" value="searchempfname" onclick="function1()">Search by Employee Name<br>
<input type="radio" name="search_emptype" value="searchemplname" onclick="function1()">Search by Employee Name<br>

<input type="text" name="text1" size="10">
<input id="empsearchbut" type="button" name="empsearch" size="10" value="Search" onclick="function1()" >


joefawcett February 1st, 2004 07:57 AM

Your code is correct for list boxes. For radio button group you need to loop through them and pick the checked one.

function getRadioFromGroup(GroupName)

  var colButtons = document.getElementsByName(GroupName)
  for (var i = 0; i < colButtons.length; i++)
    if (colButtons[i].checked) return colButtons[i];
  return null;

//Function to call from empsearchbutton

To show value immediately as you want then change your onclick to:

in your buttons and have showValue as:

function showValue(Button)
  if (Button)
    document.searchempform.text1.value = Button.value;



All times are GMT -4. The time now is 05:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.