•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 456,195 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,943 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 2193 | Replies: 2
![]() |
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Hi All,
I have built a section for my site which is to be used by administrators, In which I have a page where I can update records within my Access DB. All of the fields work fine apart from..... The radio buttons.
Currently when updating a record and selecting for example the radio button marked "Yes", on execute I am sent to the admin homepage (which is what i want it to do) but when I view the record again in the update section the radio buttons have switched back to their original state "No"!
The database is updating correctly and I have set the value of the buttons to -1 and 0.
I had this working for a short while until I added a new Radio button field and now none of them work! (I have given both sets of radio buttons different names).
I am using Deamweaver MX2004 to create these if this is any help!
Any assistance would be appreciated.
Regards
Andy
I have built a section for my site which is to be used by administrators, In which I have a page where I can update records within my Access DB. All of the fields work fine apart from..... The radio buttons.
Currently when updating a record and selecting for example the radio button marked "Yes", on execute I am sent to the admin homepage (which is what i want it to do) but when I view the record again in the update section the radio buttons have switched back to their original state "No"!
The database is updating correctly and I have set the value of the buttons to -1 and 0.
I had this working for a short while until I added a new Radio button field and now none of them work! (I have given both sets of radio buttons different names).
I am using Deamweaver MX2004 to create these if this is any help!
Any assistance would be appreciated.
Regards
Andy
•
•
Join Date: Feb 2007
Location: London
Posts: 114
Reputation:
Rep Power: 2
Solved Threads: 8
Re: Arrrgggghhhh... Radio Buttons are the bain of my life! Can someone please help.
#2
May 6th, 2007
The main problem with this sort of thing is asp is that you don't have data types for variables. That means whenever you do a compare to determine which radio button to select you must cast the data into the same types.
Hence
If databaseField1 = -1 Then
Needs to be
If cInt(databaseField1) = -1 Then
This needs to be done all the time in ASP, it can drive you a little nuts
Hence
If databaseField1 = -1 Then
Needs to be
If cInt(databaseField1) = -1 Then
This needs to be done all the time in ASP, it can drive you a little nuts
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Arrrgggghhhh... Radio Buttons are the bain of my life! Can someone please help.
#3
May 6th, 2007
Thanks for the response earlier, However, I am home from work now and just spent the last 2 - 3 hours going through the code again and even created a new page just to make sure. The same is still happening as before!
All checked values are correct and in the Select value equal to field "<%= (Ammendproductdetails.Fields.Item("InStock").Value) %>" is entered.
My other radio buttons are exactly the same but with different name and "<%= (Ammendproductdetails.Fields.Item("SpecialOffer").Value) %>" is the equal to value.
My Code above the HTML reads like this (I understand that dreamweaver inserts loads of useless stuff!)....
<!--#include file="../Connections/DB.asp" -->
<%
// *** Edit Operations: declare variables
// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}
// boolean to abort record edit
var MM_abortEdit = false;
// query string to execute
var MM_editQuery = "";
%>
<%
// *** Update Record: set variables
if (String(Request("MM_update")) == "form1" &&
String(Request("MM_recordId")) != "undefined") {
var MM_editConnection = MM_DB_STRING;
var MM_editTable = "Products";
var MM_editColumn = "ProductCode";
var MM_recordId = "'" + Request.Form("MM_recordId") + "'";
var MM_editRedirectUrl = "Admin_index.asp";
var MM_fieldsStr = "ProductName|value|ProductDescription|value|IntheBox|value|ProductSpec|
value|ProductColour|value|ProductPrice|value|DeliveryPrice|value|ProductPicture|value|
SavingPicture|value|InStock|value|Keywords|value|SpecialOffer|value";
var MM_columnsStr = "ProductName|',none,''|ProductDescription|',none,''|IntheBox|',none,''|ProductSpec|',none,''|
ProductColour|',none,''|ProductPrice|none,none,NULL|DeliveryPrice|none,none,NULL|ProductPicture|
',none,''|SavingPicture|',none,''|InStock|none,-1,0|Keywords|',none,''|SpecialOffer|none,-1,0";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Update Record: construct a sql update statement and execute it
if (String(Request("MM_update")) != "undefined" &&
String(Request("MM_recordId")) != "undefined") {
// create the sql update statement
MM_editQuery = "update " + MM_editTable + " set ";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_editQuery += ((i != 0) ? "," : "") + MM_columns[i] + " = " + formVal;
}
MM_editQuery += " where " + MM_editColumn + " = " + MM_recordId;
if (!MM_abortEdit) {
// execute the update
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}
}
%>
<%
var Ammendproductdetails = Server.CreateObject("ADODB.Recordset");
Ammendproductdetails.ActiveConnection = MM_AucklandElectricalsDB_STRING;
Ammendproductdetails.Source = "SELECT * FROM Products";
Ammendproductdetails.CursorType = 0;
Ammendproductdetails.CursorLocation = 2;
Ammendproductdetails.LockType = 1;
Ammendproductdetails.Open();
var Ammendproductdetails_numRows = 0;
%>
The Radio Buttons are as follows:
In Stock:
Yes:<input <%=(((Ammendproductdetails.Fields.Item("InStock").Value) == -1)?"CHECKED":"")%> name="InStock" type="radio" value="-1">
No:<input <%=(((Ammendproductdetails.Fields.Item("InStock").Value) == 0)?"CHECKED":"")%> name="InStock" type="radio" value="0" checked>
On Offer:
Yes:<input <%=(((Ammendproductdetails.Fields.Item("SpecialOffer").Value) == -1)?"CHECKED":"")%> name="SpecialOffer" type="radio" value="-1">
No:<input <%=(((Ammendproductdetails.Fields.Item("SpecialOffer").Value) == 0)?"CHECKED":"")%> name="SpecialOffer" type="radio" value="0" checked>
All checked values are correct and in the Select value equal to field "<%= (Ammendproductdetails.Fields.Item("InStock").Value) %>" is entered.
My other radio buttons are exactly the same but with different name and "<%= (Ammendproductdetails.Fields.Item("SpecialOffer").Value) %>" is the equal to value.
My Code above the HTML reads like this (I understand that dreamweaver inserts loads of useless stuff!)....
<!--#include file="../Connections/DB.asp" -->
<%
// *** Edit Operations: declare variables
// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}
// boolean to abort record edit
var MM_abortEdit = false;
// query string to execute
var MM_editQuery = "";
%>
<%
// *** Update Record: set variables
if (String(Request("MM_update")) == "form1" &&
String(Request("MM_recordId")) != "undefined") {
var MM_editConnection = MM_DB_STRING;
var MM_editTable = "Products";
var MM_editColumn = "ProductCode";
var MM_recordId = "'" + Request.Form("MM_recordId") + "'";
var MM_editRedirectUrl = "Admin_index.asp";
var MM_fieldsStr = "ProductName|value|ProductDescription|value|IntheBox|value|ProductSpec|
value|ProductColour|value|ProductPrice|value|DeliveryPrice|value|ProductPicture|value|
SavingPicture|value|InStock|value|Keywords|value|SpecialOffer|value";
var MM_columnsStr = "ProductName|',none,''|ProductDescription|',none,''|IntheBox|',none,''|ProductSpec|',none,''|
ProductColour|',none,''|ProductPrice|none,none,NULL|DeliveryPrice|none,none,NULL|ProductPicture|
',none,''|SavingPicture|',none,''|InStock|none,-1,0|Keywords|',none,''|SpecialOffer|none,-1,0";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Update Record: construct a sql update statement and execute it
if (String(Request("MM_update")) != "undefined" &&
String(Request("MM_recordId")) != "undefined") {
// create the sql update statement
MM_editQuery = "update " + MM_editTable + " set ";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_editQuery += ((i != 0) ? "," : "") + MM_columns[i] + " = " + formVal;
}
MM_editQuery += " where " + MM_editColumn + " = " + MM_recordId;
if (!MM_abortEdit) {
// execute the update
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}
}
%>
<%
var Ammendproductdetails = Server.CreateObject("ADODB.Recordset");
Ammendproductdetails.ActiveConnection = MM_AucklandElectricalsDB_STRING;
Ammendproductdetails.Source = "SELECT * FROM Products";
Ammendproductdetails.CursorType = 0;
Ammendproductdetails.CursorLocation = 2;
Ammendproductdetails.LockType = 1;
Ammendproductdetails.Open();
var Ammendproductdetails_numRows = 0;
%>
The Radio Buttons are as follows:
In Stock:
Yes:<input <%=(((Ammendproductdetails.Fields.Item("InStock").Value) == -1)?"CHECKED":"")%> name="InStock" type="radio" value="-1">
No:<input <%=(((Ammendproductdetails.Fields.Item("InStock").Value) == 0)?"CHECKED":"")%> name="InStock" type="radio" value="0" checked>
On Offer:
Yes:<input <%=(((Ammendproductdetails.Fields.Item("SpecialOffer").Value) == -1)?"CHECKED":"")%> name="SpecialOffer" type="radio" value="-1">
No:<input <%=(((Ammendproductdetails.Fields.Item("SpecialOffer").Value) == 0)?"CHECKED":"")%> name="SpecialOffer" type="radio" value="0" checked>
Last edited by Andy Greenwood : May 6th, 2007 at 7:30 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- javascript radio buttons and insanity (JavaScript / DHTML / AJAX)
- dynamically generated textboxes & radio buttons php, insert into db (PHP)
- binding radio buttons (VB.NET)
- javascript: radio buttons (JavaScript / DHTML / AJAX)
- IE6 - dialogue boxes , check boxes and radio buttons work very slowly after hijacking (Viruses, Spyware and other Nasties)
Other Threads in the ASP Forum
- Previous Thread: Accept/Decline Registration
- Next Thread: alternative to inet control


Linear Mode