Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Updating the value in a radio button from a text field

Guest
Apr 30, 2011 Apr 30, 2011

I have a form where an administrator can assign a volunteer to a specific activity. To do this I used radio buttons and that worked fine, but now my users want an extra button labelled "Other" and then they can type in an activity in a text field. I have this almost working but I am unable to copy the value in the text field to the radio button value, when I submit the form the button value continues to be "other", i.e. the text field value is not overwriting the button value. Here's the code for the button and text fields (simplified a bit to remove the spry code that sets the button as "Checked")

<input type="radio" name="assignedactivity" value="other" />       
          Other...Please specify<br />
<input type="text" name="otherActivity" onsubmit="copyIt()" />

and here's the code for copyIt()

<script type = "text/javascript">
function copyIt() {
x = document.getElementById("otherActivity").value;
document.getElementById("assignedactivity").value = x;
}
</script>

I'd really appreciate it if someone could tell me what I did wrong.

Thanks,

Tony

TOPICS
Server side applications
872
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 01, 2011 May 01, 2011

I've tried a few more things to no avail. Here's a little more info that may pinpoint the problem. I'm getting a javascript error on this line in the copyit function

x = document.getElementById("otherActivity").value;

The error is SCRIPT 5007: Unable to get value of the property 'value' : object is null or undefined

So, it looks like it's not finding the text field for some reason. Any ideas, anyone?

I've spent several hours on this now, I must be missing something blindingly obvious. Thanks for any pointers you can provide.

Tony

Message was edited by: tonybabb

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011
LATEST

Never mind - I created a very simple page and posted the question here and it was answered. If anyone else has the same problem here's what it took.

The problem:

I had a list of radio buttons and the user selected one of them. The last one was marked "Other", if the user selected this they could type text into a text box and the text was then moved to the the radio button as a value. Javascript was failing saying it couldn't find the text box.

The solution:

I was using GetElementById to reference the text field and the radio button but I had omitted to assign an ID to each, once I did that it worked.

Thanks all.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines