473,396 Members | 1,785 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,396 software developers and data experts.

How to update the radio button value in the database using ASP

Hi ,
I am creating webpage in ASP. In that page i am using 2 radio button.....
Male and female

If onclick event fires for the radiobutton i have to update the value in the database as male (if i checked the male).....

Using Javascript i am getting the value of the radiobutton value and placing them in the hiddenbox and then in the ASP code i get the value of the hiddenbox using request.form and then update the same value in the database...

My problem here is since the page is reloaded i am getting the Null value .......in the ASP code...(SInce ASP runs all the code before)


Pls help me ....
Jan 2 '08 #1
4 4997
idsanjeev
241 100+
Hi
sona you know that asp page forgate all value after reload pages so plz check out the request value is stored or not
show your code where you store and call on next
Jan 2 '08 #2
Javascript code

function function(gen)
{


document.getElementById("gender").value = gen;


}

<form action="page.asp" method="post" >
<input type="radio" id="sam1" name="Radio" onclick ="function('male')" value="male" />Male <br />
<input type="radio" id="sam2" name="Radio" onclick = "function('female')" value="female"/>Female
<input type="hidden" id="hid1">&nbsp
<input type="button" value="click!!" id="submit" > <br><br></center>
<input type="text" id="gender" name="status" >
</form>

ASP code

<%
Dim gend
gend = Request.Form ("status")
if gend <> "" then
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Mode = 3 '3 = adModeReadWrite
objConn.Open "Excel"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.ActiveConnection = objConn
objRS.CursorType = 3 'Static cursor.
objRS.LockType = 2 'Pessimistic Lock.
objRS.Source = "Select * from Range1"
objRS.Open



objRS.MoveFirst
objRS.Fields(0).Value = status1
objRS.Update



objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing

Else
Response.write "Nothing"

End if
Thanx for
Jan 2 '08 #3
idsanjeev
241 100+
Hi sona
I can't understand
so please read this then try to arrang your code

Radio
Jan 3 '08 #4
Nicodemas
164 Expert 100+
Sonasang:

There are some problems with your script; you are doing some unnecessary steps here.

What is the name of the field you are trying to update?

Radio buttons can be read by ASP via the Request object. You do not need to update the hidden form field with the user's gender selection. Use Request.Form("Radio") to get the value the user selected.

Also, the script you use to update your database is doing a lot more than it really should. I did not see anywhere in that script where you set a variable called status1, either. Try this...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim gend
  3. gend = Request.Form ("Radio")
  4.  
  5. if gend = "male" or gend = "female" then
  6. Set objConn = Server.CreateObject("ADODB.Connection")
  7. objConn.Mode = 3 '3 = adModeReadWrite
  8. objConn.Open "Excel"
  9.  
  10. Set objRS = Server.CreateObject("ADODB.Recordset")
  11. objRS.ActiveConnection = objConn
  12. objRS.Source = "UPDATE Range1 SET fieldName = '"& gend &"' WHERE fieldID = ID"
  13. objRS.Open
  14. ... etc...
  15.  
All you have to do is UPDATE the database, so use an UPDATE sql query. In my query above, I put two variable field names which you should replace with your own.

fieldName = the field you are updating
fieldID = the unique field of your table - your primary key

I also put a variable in called ID.
ID = the value of the primary key for the record you are updating.
Jan 6 '08 #5

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

Similar topics

4
by: Jay | last post by:
I have a form used to submit data (no surprises there!). I'd like to be able to populate the same form with previously submitted data. The data lives in a database once submitted and using ASP I...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
7
by: nathaniel.k.lee | last post by:
Is it not possible, in IE, to dynamically click a radio button? I'm grabbing some values from a database and using them to populate radio buttons on a page. I have alternate code for Firefox...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
10
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...
3
by: mountain.dog | last post by:
I have a query that shows a list of options that a user can toggle on or off using a checkbox. query... form... while($row = mysql_fetch_array($result))... <input name="menu_show_attribute"...
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...
5
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.