473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Setting checked of Radio from ASP

Hey there,

Im relatively new to ASP and am having a bit of a situation and so far google hasn't been too helpful! so hopefully someone here can help!

Heres is the situation.

I have a form with a bunch of text and radio fields that load up empty or with some default radio value. what im trying to do is based on a DB Query if there is a ?recordId= in the url, if the record already exists have the fields filled in so they can be editted.

I haven't had any problems changing the text fields. I just used ASP to write some Response.write some java script basically doing

FormName.FieldName.value =

and it works fine.

What i cant figure out is how you can change radio values checked values using a similar method.

If anyone can help me out please let me know!! thank you! :)

Miles!

P.S. If it helps here is how the radios are set up. This is default if it is a new record. Each responsibility has 3 radio options associated with it. Add, Delete, and No Change. But the number of responsibilities is dynamic and queried from database.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <%
  4. SQL_query1 = "SELECT * FROM casResponsibility ORDER BY casGroup ASC"
  5. Set RS1 = MyConn.Execute(SQL_query1) 
  6. %>
  7.  
  8. <tr> 
  9. <td><input name="<%=RS1("casRespId")%>" type='radio' value='add' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','block');changeDiv('" & RS1("casRespId") & "delete','none')")%>" /></td>
  10. <td><input name="<%=RS1("casRespId")%>" type='radio' value='delete' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','none');changeDiv('" & RS1("casRespId") & "delete','block')")%>" /></td> 
  11. <td><input name="<%=RS1("casRespId")%>" type='radio' value='nochange' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','none');changeDiv('" & RS1("casRespId") & "delete','none')")%>" checked="checked" /></td> 
  12.  
  13. <td><%=RS1("casGroup")%>-<%=RS1("casTask")%></td>
  14.  
  15. </tr>
  16.  
  17. <% RS1.MoveNext %>
  18. <% WEND %>
  19.  
Jan 26 '09 #1
3 1927
jhardman
3,406 Expert 2GB
As an ASP user, I would have to say that using asp to send a javascript command to change the value of a field is not the easy way to do it. All you need to do is use ASP to fill in the value of the field as you write it:
Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2.  <td><input name="<%=RS1("casRespId")%>" type="radio" value="add" onclick="changeDiv('<%=RS1("casRespId")%>add', 'block'); changeDiv('<%= RS1("casRespId")%>delete','none')" 
  3. <% if not RS1.eof then response.write "Checked=" & chr(34) & "checked" & chr(34) %>
  4. /></td>
I wasn't sure exactly which field you were checking, So my if statement just says if the recordset hasn't reached the end, then print "checked", I know there is probably no reason to write that, but hopefully it demonstrates what I am saying. Instead of generating javascript to change the value after it has been written, ASP's strength is altering the text and filling in blanks BEFORE it goes to the browser. Does this make sense?

Jared
Jan 28 '09 #2
That is prefect thank you! i had wanted to do something like that but i couldnt figure out how to do 3 levels of " marks. but using char(34) is exactly what i needed. thanks!
Jan 28 '09 #3
jhardman
3,406 Expert 2GB
Another way to add quote marks without escaping them:
Expand|Select|Wrap|Line Numbers
  1. dim q
  2. q = chr(34) %>
  3. <tr>
  4. <td><input name="<%=RS1("casRespId")%>" type="radio" value="add" onclick="changeDiv('<%=RS1("casRespId")%>add', 'block'); changeDiv('<%= RS1("casRespId")%>delete','none')"
  5. <% if not RS1.eof then response.write "Checked=" & q & "checked" & q %>
  6. /></td>
Jared
Jan 28 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Greg | last post by:
I'm trying to set a group of radio buttons based on the value of a text field in a dataset. This is my code: Dim ds As DataSet ds = dtsVideo Dim dt As DataTable = ds.Tables("tblPeramItems")...
1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
6
by: Ken Loomis | last post by:
Hello: On a web page I check the value of a cookie and set one of two radio buttons accordingly. function setRadioForm() { var myCookie = document.cookie; var OpenOnly =...
1
by: Jim | last post by:
I have a 2 checkboxes and a hidden field..what I want to happen is that you can only click on 1 of these checkboxes at a time and when you check a checkbox it will assign the hidden field...
0
by: tshad | last post by:
I am trying to set my radio buttons Programmatically. But no matter what I do - the 3rd one is always checked - even though I can tell my my trace statements the other buttons were the ones set. ...
3
by: rob c | last post by:
Hi I'm not sure if this is the right place to ask for help on forms and radio buttons... In the following form, I'd like to set the value of 'item_name' based on which radio button was...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
7
by: IchBin | last post by:
I am trying to programmatically set a radio button in a table of radio buttons. I have two problems with the code below: 1 - I can not prepare the <Formstatement to be printed by php. (syntax...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.