Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2004, 02:21 AM
Authorized User
Join Date: Oct 2003
Location: KL, wilayah persekutuan, Malaysia.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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()" >


Reply With Quote
  #2 (permalink)  
Old February 1st, 2004, 07:57 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

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;

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
binding textboxes to selected radio button abhi_loveu2002 ASP.NET 2.0 Basics 0 December 20th, 2006 05:54 AM
show dynamic textbox when radiobuttonlist selected debjanib ASP.NET 1.0 and 1.1 Professional 1 May 30th, 2006 09:42 PM
Toggle active state of textbox with a radio button Hatchingabrain Javascript How-To 2 April 4th, 2005 07:13 AM
Page display based on radio button selected Mekala HTML Code Clinic 3 July 10th, 2004 06:12 AM
Update textbox when List menu is Selected rylemer Javascript 3 November 11th, 2003 10:53 AM

All times are GMT -4. The time now is 06:17 AM.

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