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

Checkboxes - invalid use of CStr?

LEGEND ,
Nov 27, 2006 Nov 27, 2006
What is wrong with this for a radio group? My field "vatregistered" is an
INT field in a SQL database and I'm using ASP/VBScript.

<input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
CStr("1")) Then Response.Write("checked=""checked""") : Response.Write("")%>
name="vatregistered" type="radio" value="1" />
Yes
<input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
CStr("0")) Then Response.Write("checked=""checked""") : Response.Write("")%>
name="vatregistered" type="radio" value="0" checked="checked" />
No

This produces the following error:

Error Type:
Microsoft VBScript runtime (0x800A005E)
Invalid use of Null: 'CStr'

What gives? I just used the DW wizard to create this, so I'm puzzled.
Thanks again.

Regards
Nath.


TOPICS
Server side applications
820
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
LEGEND ,
Nov 27, 2006 Nov 27, 2006
I've hand coded it to this:

<input <%If ((rsDetails.Fields.Item("vatregistered").Value) = 1) Then
Response.Write("checked=""checked""") : Response.Write("")%>
name="vatregistered" type="radio" value="1" />
Yes
<input <%If ((rsDetails.Fields.Item("vatregistered").Value) = 0) Then
Response.Write("checked=""checked""") : Response.Write("")%>
name="vatregistered" type="radio" value="0" />
No

But, whilst this doesn't produce an error, when the page re-loads (this is
all within an UPDATE page which submits to itself), the values aren't
displayed for the checkbox. In other words, they are both blank where one
of them should be checked.

Can anyone see what's wrong with the above?

This is a basic UPDATE form with a radio group - Yes or No. This stores to
a record in the database.
When the page initially loads, I'd like the radio group to display the value
held in database (either yes/no - my database field is SQL "bit" type).

Hope someone can help. Thanks.

Thanks
Nath.


"tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
news:ekf9of$nha$1@forums.macromedia.com...
> What is wrong with this for a radio group? My field "vatregistered" is an
> INT field in a SQL database and I'm using ASP/VBScript.
>
> <input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
> CStr("1")) Then Response.Write("checked=""checked""") :
> Response.Write("")%> name="vatregistered" type="radio" value="1" />
> Yes
> <input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
> CStr("0")) Then Response.Write("checked=""checked""") :
> Response.Write("")%> name="vatregistered" type="radio" value="0"
> checked="checked" />
> No
>
> This produces the following error:
>
> Error Type:
> Microsoft VBScript runtime (0x800A005E)
> Invalid use of Null: 'CStr'
>
> What gives? I just used the DW wizard to create this, so I'm puzzled.
> Thanks again.
>
> Regards
> Nath.
>


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
LEGEND ,
Nov 28, 2006 Nov 28, 2006
Had to ditch it and change to check boxes!
Radio groups - nightmare for an INSERT or UPDATE!

Nath.

"tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
news:ekfblq$q37$1@forums.macromedia.com...
> I've hand coded it to this:
>
> <input <%If ((rsDetails.Fields.Item("vatregistered").Value) = 1) Then
> Response.Write("checked=""checked""") : Response.Write("")%>
> name="vatregistered" type="radio" value="1" />
> Yes
> <input <%If ((rsDetails.Fields.Item("vatregistered").Value) = 0) Then
> Response.Write("checked=""checked""") : Response.Write("")%>
> name="vatregistered" type="radio" value="0" />
> No
>
> But, whilst this doesn't produce an error, when the page re-loads (this is
> all within an UPDATE page which submits to itself), the values aren't
> displayed for the checkbox. In other words, they are both blank where one
> of them should be checked.
>
> Can anyone see what's wrong with the above?
>
> This is a basic UPDATE form with a radio group - Yes or No. This stores
> to a record in the database.
> When the page initially loads, I'd like the radio group to display the
> value held in database (either yes/no - my database field is SQL "bit"
> type).
>
> Hope someone can help. Thanks.
>
> Thanks
> Nath.
>
>
> "tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
> news:ekf9of$nha$1@forums.macromedia.com...
>> What is wrong with this for a radio group? My field "vatregistered" is
>> an INT field in a SQL database and I'm using ASP/VBScript.
>>
>> <input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
>> CStr("1")) Then Response.Write("checked=""checked""") :
>> Response.Write("")%> name="vatregistered" type="radio" value="1" />
>> Yes
>> <input <%If (CStr((rsDetails.Fields.Item("vatregistered").Value)) =
>> CStr("0")) Then Response.Write("checked=""checked""") :
>> Response.Write("")%> name="vatregistered" type="radio" value="0"
>> checked="checked" />
>> No
>>
>> This produces the following error:
>>
>> Error Type:
>> Microsoft VBScript runtime (0x800A005E)
>> Invalid use of Null: 'CStr'
>>
>> What gives? I just used the DW wizard to create this, so I'm puzzled.
>> Thanks again.
>>
>> Regards
>> Nath.
>>
>
>


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
LEGEND ,
Nov 28, 2006 Nov 28, 2006

"tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
news:ekh97p$5tr$1@forums.macromedia.com...
> Had to ditch it and change to check boxes!
> Radio groups - nightmare for an INSERT or UPDATE!
>
> Nath.

Radio groups are easy for insert and update. Your problem is a lack of
understanding regarding your data types.
NULL <> 0 and NULL <> 1, so when you have a NULL value (which is also what
caused your "invalid use of CStr" error), neither button will be selected if
you're checking for equality both times. If something MUST be selected,
then use = for the first test and <> for the second. Also, the SQL Server
BIT type needs no comparison - it is in itself a true or false value.

<%
If myRS.Fields.Item("someBIT").Value Then
%>

etc.


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
LEGEND ,
Nov 28, 2006 Nov 28, 2006
Don't mean to sound picky here Lion, but I am using Dreamweaver's "Wizards"
to create the Update and Insert forms that don't work - I'm not sure that
it's 100% my lack of understanding considering that I'm being led down the
garden path a bit by DW. :o) What you're saying is that the DW wizards
don't create the code correctly, right?

In all honesty, I just gave up on radio groups on my Insert/Update forms
because I just couldn't get them to work using DW and I don't have the ASP
knowledge to hand code it (which is why I bought DW). Next time I'm doing
it, I'll have a crack at hand coding those bits.

I appreciate your advice, again. Thank you.
Regards
Nath.

"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:ekho0p$nb8$1@forums.macromedia.com...
>
> "tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
> news:ekh97p$5tr$1@forums.macromedia.com...
>> Had to ditch it and change to check boxes!
>> Radio groups - nightmare for an INSERT or UPDATE!
>>
>> Nath.
>
> Radio groups are easy for insert and update. Your problem is a lack of
> understanding regarding your data types.
> NULL <> 0 and NULL <> 1, so when you have a NULL value (which is also what
> caused your "invalid use of CStr" error), neither button will be selected
> if you're checking for equality both times. If something MUST be
> selected, then use = for the first test and <> for the second. Also, the
> SQL Server BIT type needs no comparison - it is in itself a true or false
> value.
>
> <%
> If myRS.Fields.Item("someBIT").Value Then
> %>
>
> etc.
>


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
LEGEND ,
Nov 28, 2006 Nov 28, 2006
LATEST
"tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
news:ekhtdu$lc$1@forums.macromedia.com...
> Don't mean to sound picky here Lion, but I am using Dreamweaver's
> "Wizards" to create the Update and Insert forms that don't work - I'm not
> sure that it's 100% my lack of understanding considering that I'm being
> led down the garden path a bit by DW. :o) What you're saying is that
> the DW wizards don't create the code correctly, right?

DW's wizards, despite the name, are not magical. :)
In a situation where there is always a value, the automatic code would be
correct. Some of DW's behaviors handle NULL values and some don't. Part of
using the wizards is understanding your underlying data and the restrictions
of particular behaviors.

I will concede that ALL of DW's behaviors should handle a NULL value without
throwing an error, though.


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