Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 scripting a radio buttons checked property
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 08 June 2001 :  07:04:33  Show Profile
I am trying to set a radio buttons checked property depending on a Yes/No field in a database. Anyone know why this won't work:
<SCRIPT LANGUAGE="JavaScript">
function setRadios() {
if ( <%=oRS("RadioButtonValue")%>="yes") {
document.myForm.R1[0].checked
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD="POST" NAME=myForm>
<P><INPUT TYPE="radio" VALUE="Yes" NAME="R1">Yes</P>
<P><INPUT TYPE="radio" VALUE="No" NAME="R1">No</P>
<P><INPUT TYPE="button" VALUE="Set Checked" NAME="B1" onClick="setRadios()">
</FORM></BODY></HTML>



K
Starting Member

14 Posts

Posted - 08 June 2001 :  10:56:26  Show Profile
Might you need to pass the asp variable into the function and then use it? Have you tried writing out within the function (document.write) what you have in that variable just to check that you do have it first?

Not sure if this will help but maybe it's worth a try...

Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 08 June 2001 :  11:54:40  Show Profile
I did try that, the problem seems to be in the javascript rather than the vbscript, for instance this does not work either and there's no ASP or vbscript in it.
<SCRIPT LANGUAGE="JavaScript">
function setRadios() {
document.myForm.R1[0].checked
}
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD="POST" NAME=myForm>
<P><INPUT TYPE="radio" VALUE="Yes" NAME="R1">Yes</P>
<P><INPUT TYPE="radio" VALUE="No" NAME="R1">No</P>
<P><INPUT TYPE="button" VALUE="Set Checked" NAME="B1" onClick="setRadios()">
</FORM></BODY></HTML>

I must be getting something wrong in the javascript, anyone got any ideas what?




Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 08 June 2001 :  15:33:59  Show Profile
I don't understand what you're trying to do.
When the user clicks on a radio button, what do you want happen?

Go to Top of Page

K
Starting Member

14 Posts

Posted - 11 June 2001 :  03:21:55  Show Profile
I think what TerryG is trying to do is to initialise the radio buttons to checked/unchecked depending on the database value.

TerryG:
My suggestion does relate to the javascript. You are referring to the recordset data in the javascript function, but you haven't actually passed it in as a parameter. You'd need to do something like calling this function within a recordset loop for each item.

i.e. when you retrieve the recordset values, loop through each one using recordsetname.movenext and call that function, but pass the recordset value (<%=oRS("RadioButtonValue")%> as a parameter.

As an example:

Call it within the recordset loop like this:


setRadios(<%=oRS("RadioButtonValue")%>)

and the script would be:

<SCRIPT LANGUAGE="JavaScript">
function setRadios(RadioButtonValue)
{
if (RadioButtonValue == "yes")
{
document.myForm.R1[0].checked
}
}
</SCRIPT>


This is just a rough example, but you can hopefully get the idea. You'll need to mess around with it to perhaps pass it the radio button element number R1[count] instead of R1[0] perhaps?

Hope this helps a little.

K

Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 11 June 2001 :  05:23:00  Show Profile
quote:

I think what TerryG is trying to do is to initialise the radio buttons to checked/unchecked depending on the database value.



Yes, thats right.

K, thanks for your detailed response. I didnt quite understand it at first so I battled on as I was doing, and to my surprise by adding "=true" to "document.myForm.R1[0].checked"
it works.
Then the penny started to drop with regard to your suggestion and although I am getting out of my depth now might it be that by using <%= I am writing the recordset value into the Javascript function before the javascript function executes, so the Javascript simply sees the value not a variable which should have been passed in? Please feel free to tell me if I have this completely wrong.

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.28 seconds. Powered By: Snitz Forums 2000 Version 3.4.07