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
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 1st, 2004, 01: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.

<html>
<head>
    <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

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

<body>
<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()" >

</form>
</body>
</html>

Reply With Quote
  #2 (permalink)  
Old February 1st, 2004, 06: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
Default

Your code is correct for list boxes. For radio button group you need to loop through them and pick the checked one.
Code:
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
onclick="showValue(getRadioFromGroup('search_emptype'));
To show value immediately as you want then change your onclick to:
Code:
onclick="showValue(this);"
in your buttons and have showValue as:
Code:
function showValue(Button)
{
  if (Button)
  {
    document.searchempform.text1.value = Button.value;
  }  
}
--

Joe
Reply With Quote
Reply


Thread Tools
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 04: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 09:53 AM



All times are GMT -4. The time now is 11:28 AM.


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