Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS HTML Interaction and Radio Buttons?

Status
Not open for further replies.

robdunfey

Technical User
Joined
Apr 26, 2002
Messages
110
Location
GB
Hi,

Two questions.

1) I cant seem to be able to write text to a textarea from my javascript file. The textarea resides in a form, in a table, on a html page stored in the same folder as the js file? I have tried using things like document.getelementbyid("myform").value="hello" and swapping document for top (whatever that means?) but cant get it to work?

2) I have a set of radio buttons, in a form, in a table in a html page. I want to execute js code in a js file when any of the buttons is a)checked or b)unchecked? Does anybody now how this may be done? Or the location of a simple to follow example?

Kind Regards,

Rob
 
try the following

<form name=&quot;myForm&quot;>
<textarea name=&quot;test&quot;></textarea>
</form>
<script language=&quot;javascript&quot;>
document.myForm.test.value='Hello';
</script>

each radio button has an onclick event, which should do what you need.
 
thanks for the swift reply.

i get an error saying document.myForm.test is null or not an obeject? does it make any difference that the html and js are stored in separate files?

thanks,

Rob
 
Hi,

I have it working. I changed 'document' to 'top', I dont know why this makes a difference but if someone could explain that would be great.

As for the radio button on click, how would you deal with it losing focus? i.e. onunclick?


Thanks,

Rob
 
The onclick event is called whenever a radio button is clicked - to turn it off or to turn it on.
 
Rob,

'top' refers to the top-level window object when your page has frames.

use onblur to capture an element losing focus.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top