473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

27 New Member
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 5049
idsanjeev
241 New Member
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
Sonasang
27 New Member
Javascript code

function function(gen)
{


document.getEle mentById("gende r").value = gen;


}

<form action="page.as p" method="post" >
<input type="radio" id="sam1" name="Radio" onclick ="function('mal e')" value="male" />Male <br />
<input type="radio" id="sam2" name="Radio" onclick = "function('fema le')" value="female"/>Female
<input type="hidden" id="hid1">&nbs p
<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.CreateOb ject("ADODB.Con nection")
objConn.Mode = 3 '3 = adModeReadWrite
objConn.Open "Excel"

Set objRS = Server.CreateOb ject("ADODB.Rec ordset")
objRS.ActiveCon nection = objConn
objRS.CursorTyp e = 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 New Member
Hi sona
I can't understand
so please read this then try to arrang your code

Radio
Jan 3 '08 #4
Nicodemas
164 Recognized Expert New Member
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("R adio") 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
3250
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 can populate text boxes/textareas using this data no problem. What about radio buttons? If I have 2 of them named the same rb1 and rb1 with values of yes/no respectively.
2
5428
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 I want to be able to retrieve the selected value from each of the sets of radio buttons.The names of each group of radio buttons is set by the database and I don't know how to retrieve the values because I don't know the names of these radio...
8
5903
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 control. See the code below * Page.aspx: <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Webspace.Test" %>
7
2530
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 browsers using the setAttribute() function. Everything works as planned in Firefox but in IE, the buttons won't populate and, what's worse, I can't even click on them after everything loads. I see the slight shadow that indicates you're clicking on a...
1
6891
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 grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
10
6101
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
3
5156
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" type="checkbox" class="checkbox"'); if ($row == 1) { echo (' value="'.$row.'" checked />
5
4155
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 MySQL database using JavaScript to find a product either by Product ID, Description, or Both. Originally, the 'Both' radio button was "checked" but I now want the 'Product ID' button set as the default choice (as you can see from the code below). ...
5
7471
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 radio buttons that I have for each one of the rows in the table. I've tried using a hidden input object for each of the radio button groups to store the values in but clearly I'm having a mental block because I can't get that to work right either. So...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9370
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.