Forum Moderators: open

Message Too Old, No Replies

help creating onclick function to fill a span

         

useless

6:36 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



I am new and not very good with JS, and am trying to create a small survey form that just has radios for the answer selections. Based on the radio selected, I am wanting to fill a <span> tag with either a correct/incorrect message (preferably different color font). The one thing that is making this difficult for me is that fact that I cannot name the form (not that I don't know how, but because I am not allowed to). I saw quite a few posts here and figured there would be some good suggestions. Anyways, thanks to those who can offer solutions.

SpaceFrog

7:51 am on Mar 1, 2005 (gmt 0)

10+ Year Member



what is this homework you are trying to do?
if you cannot name the form you can always grab handle of the form with:

document.forms[0]

useless

5:17 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Spacefrog,

No this is not homework, this is something I am trying to do and like I mentioned in my post I'm new and not very good at JS, so I find your response rather insulting.

rocknbil

5:43 pm on Mar 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well you shouldn't, I don't know how you found that insulting.

. . . I cannot name the form (not that I don't know how, but because I am not allowed to).. . .

What is not allowing you to name the form? One would naturally make the presumption that this is some form of an external restraint, such as an instructor. Additionally, I don't think SpaceFrog's first language is English.

Based on the radio selected, I am wanting to fill a <span> tag with either a correct/incorrect message (preferably different color font).

Don't know if you can to this. You'd have to regenerate the document or write your value to another text field, one that you can set the onFocus() so that it can't be edited. For example, (framework only, not tested:)

<input type="radio" onClick="addVal(this.form,'yes');" value="yes" /> Si
<input type="radio" onClick="addVal(this.form,'no');" value="yes" /> Niet
<input type="text" name="result" value="" onFocus="blur();" />
.....

function addVal(form,val) {
form.result.value=val;
}

By referencing the form with the "this" keyword it allows you to manage it as a generic object without it being specifically named. SpaceFrog's solution would work if it's the FIRST or only form on the page (forms array index 0.)

Additionally, I'm pretty sure you could set the style of the text field so that the borders don't show and it looks like a part of the page rather than a form field.

SpaceFrog

8:27 am on Mar 3, 2005 (gmt 0)

10+ Year Member



Thank's Rocknbill...
It was not meant to be insulting at all... It's just that the statment "because I'm not allowed" could be some kind of exercise ...
Moreover I don't see anything insulting in doing homeworks ... ;-)

useless

10:59 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



Spacefrog & Rocknbill,

Thanks for the replies. I can see how you may thing that by being 'not allowed' to name my form may seem like this is coming from an instructor/teacher. However, in my case maybe I should have used the word able instead of allowed. By this I mean that the way this form has been set up for me (by developers)that it uses an html tld that doesn't allow the naming of the form (does this make sense?). Anyways, that is the only reason for not being able/allowed to name the form. I apologise for finding Spacefrog's initial reply insulting, I guess when you're new and not very good at (in this case JS) and all you're looking for is an answer/help, the reponse felt like a dig at my intelligence. I appreciate the responses and advice.

Thanks!