By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

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

P: 27
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
Share this Question
Share on Google+
4 Replies


idsanjeev
100+
P: 241
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

P: 27
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
100+
P: 241
Hi sona
I can't understand
so please read this then try to arrang your code

Radio
Jan 3 '08 #4

Expert 100+
P: 164
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

Post your reply

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