473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically change text box based on radio button

I have the following. Based on which radio button is checked, I want to adjust the date that is filled in for the text box. The problem I am having is that each button fills in the same date. Am I misunderstanding what getElementById("opt1").value returns? TIA

[HTML]<html>
<head>
<script language="JavaScript">

function changeRadioButton(iDays)
{
if (document.getElementById("opt1").value == 'week')
{iDays = 7}
else
{iDays = 14 }

var myDate=new Date()
myDate.setDate(myDate.getDate()+ iDays)

document.getElementById("dateBox").value = myDate;
}
</script>
</head>
<body>
<input onclick="changeRadioButton()" type="radio" name="priority" id="opt1" >week</input>
<input onclick="changeRadioButton()" type="radio" name="priority" id="opt2" >month</input>
<input onclick="changeRadioButton()" type="radio" name="priority" id="opt3" >year</input>
<input type="text" id="dateBox" value=""/>
</body>
</html>[/HTML]
Nov 12 '07 #1
1 9988
Hi...
There's some code may be help you on the blow.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript">
  4.  
  5. function changeRadioButton(el){
  6.     var iDays;
  7.     if (el.value == 'week'){
  8.         iDays = 7
  9.     }else if(el.value == 'month'){
  10.         iDays = 14
  11.     }else{
  12.         iDays = 0;
  13.     }
  14.  
  15.     var myDate=new Date()
  16.     myDate.setDate(myDate.getDate()+ iDays)
  17.     document.getElementById("dateBox").value = myDate;
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <input onclick="changeRadioButton(this)" type="radio" value="week">week</input>
  23. <input onclick="changeRadioButton(this)" type="radio" value="month">month</input>
  24. <input onclick="changeRadioButton(this)" type="radio" value="year">year</input>
  25. <input type="text" id="dateBox" value=""/>
  26. </body>
  27. </html>
  28.  
You have't use this keyword and assign the value of input elements.
Nov 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
2
by: epigram | last post by:
I'm dynamically creating a number of radio buttons on my aspx page based upon data read from a db. Each radio button has autopostback turned on. I'm experiencing two problems. 1) I am reading...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: santhosh89 | last post by:
hi guys, see i want to develop a script and developed one but it s not working. the concept is there will be three radio buttons. the user has to check one radio button and click the button next...
11
by: bharathmngl | last post by:
now iam trying to add rows dynamically into the table when i click "ADD ROW" button. It should also have the option to delete the selected row. So Please help me to find code.... And also please...
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
4
by: ameshkin | last post by:
Hi Everybody, I'm just now learning javascript and I'm using mootools. What I want to do is to dynamically load a php page into accordian panel 2, depending on which radio button is selected in...
1
by: ramel | last post by:
Hi all, I have a problem related to javascript , ajax and jsp. Please see this url http://xil.co.in/print_screen_2.JPG. I am working on this form. There are some buttons (like submit ,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.