Question

problems populating form data from database

Asked by: gpyper

I'm using the following code to pull productnames and extensions of the products into a form, and I want to submit the data back to the database later.

The problem is with this bit of code

<option value="location.href='existingRecord.asp?str=<%=objRS("ProductName")%>'" <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>> <%=objRS("ProductName")%></option>

in the source of the working page the Value of the string ends up apearing as a large string including "location.href='existingRecord.asp?str=<%" instead of just the ProductName.

Can anything be done to fix this?
And is there a way of getting around the page submitting to itself? can this be done in the background?

 




 <td>Product Type&nbsp;<%
Dim ConnString
ConnString = "DSN=DBSERVER;uid=dba;pwd=test"
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = ConnString
objConn.Open
%>
<%
dim objSQL, objRS
objSQL = "select ProductName from SerialRanges where Status = 'A' and PType ='x' "
set objRS = objConn.execute(objSQL)
%>
<script language="Javascript">
function doSel(obj)
{
  for (i = 0; i < obj.length; i++)
     if (obj[i].selected == true)
       eval(obj[i].value);
}
</script>
<select name="ProductName" Class="form" onchange="doSel(this)">
<%
do while not objRS.EOF
%>
<option value="location.href='existingRecord.asp?str=<%=objRS("ProductName")%>'" <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>> <%=objRS("ProductName")%></option>
<%
objRS.movenext
loop
%>
</select>
<%
objRS.close
set objRS = nothing
%>
</td>
    <td>Units <input type="text" name="Units" size="5" class="form"></td>
    <td>From: XX-XX-XXXX To:  XX-XX-XXXX </td>
</tr>
</table>
</td>
</tr>
<tr>
    <td colspan="2"><table class="cellborder_content3" width="100%" cellspacing="0" cellpadding="3" border="0">
     <tr><td class="cellborder_content3_purple">Extensions</td></tr></table>
     <table class="cellborder_content3" width="100%" cellspacing="0" cellpadding="3" border="0">
     <tr>
<%
if request.querystring("str") <> "" then

Dim objConn1
Set objConn1 = Server.CreateObject("ADODB.Connection")
objConn1.ConnectionString = ConnString
objConn1.Open
%>
<tr><td width="33%">Name</td><td width="33%">Units</td><td width="33%">Expiery Date</td></tr>
<%
dim objSQL1, objRS1
objSQL1 = "select ProductName from SerialRanges where PType = '" & request.querystring("str") & "'"
set objRS1 = objConn1.execute(objSQL1)
do while not objRS1.EOF
%>

 <tr>  <td><input type="checkbox" name="chkbox" value="<%=objRS1("ProductName")%>"><%=objRS1("ProductName")%></td>
   <td><input type="text" name="<%=objRS1("ProductName")%>Units" size="5" class="form"></td>
   <td><input class="form" name="<%=objRS1("ProductName")%>ExpieryDate" type="text" size="10" /> <a href="javascript:calendar_window=window.open('calendar.aspx?formname=license_activation.<%=objRS1("ProductName")%>ExpieryDate','calendar_window','width=154,height=188');calendar_window.focus()"><img src="images/calendar.gif" width="22" height="17" alt="" border="0"></a></td></tr>
<%
objRS1.movenext
loop

objRS1.close
set objRS1 = nothing
end if
%>

<%
objConn.close
set objConn  = nothing
%>

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-01-30 at 08:26:31ID20489507
Tags

objsql

Topic

Active Server Pages (ASP)

Participating Experts
9
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Onchange
    Hi Experts, I have 2 related problems. First some background... I have a form and when a field called 'DateCompleted' is updated, a checkbox is automatically checked using the following onchange code <script language="JavaScript"> function chkCPCheck(ctr...
  2. Fire OnChange event without submitting form?
    Hi all. I'm trying to make a set of combo boxes. Both are populated from diffent tables in my db. The first field is Category1. It represents a list of Employment categories. The second field is EmpCat1. It represents a list of Employers in that category. I've got the ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: hongjunPosted on 2003-01-30 at 08:29:16ID: 7846842

Do this then
<option value='<%=objRS("ProductName")%>' <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>><%=objRS("ProductName")%></option>


hongjun

 

by: jitgangulyPosted on 2003-01-30 at 08:33:55ID: 7846867

Why don't  you use location.href from javascript itself. If URL its constant, just use it from javascript and keep only data value in value os of option

<option value="<%=objRS("ProductName")%>" <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>> <%=objRS("ProductName")%></option>

and in javascript

function doSel(obj)
{
 for (i = 0; i < obj.length; i++)
    if (obj[i].selected == true)
      eval(obj[i].value);
}
location.href='existingRecord.asp?str=<%=objRS("ProductName")%>'
</script>

P.S. <%=%>  asp tag will work in javascript



 

by: gpyperPosted on 2003-01-30 at 08:36:06ID: 7846887

no that code does not work

, If you look the other field is being populated based on the initial product selection

 

by: gpyperPosted on 2003-01-30 at 08:37:54ID: 7846898

sorry last was aimed at hongjun

 

by: gpyperPosted on 2003-01-30 at 08:40:30ID: 7846921

jitganguly   The page just loops in a loading state

 

by: bukkoPosted on 2003-01-30 at 08:46:09ID: 7846972


ASP is getting confused between your delimiters.

Try the following:

Dim strOption

strOption = "<option value=""location.href='existingRecord.asp?str=" & objRS("ProductName") & "'"""
If Request.QueryString("str") = objRS("ProductName") Then
  strOption = strOption & " selected"
End If
strOption = strOption & ">" & objRS("ProductName") & "</option>"
Response.Write strOption

This should work!

Regards

bukko

 

by: MaxOvrdrvPosted on 2003-01-30 at 08:48:08ID: 7846991

hehe: javascript is the answer alright:

<option value="JavaScript:location.href='existingRecord.asp?str=<%=objRS("ProductName")%>'" <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>> <%=objRS("ProductName")%></option>

simply add the "JavaScript:" perogative before your statement... ;)

Max!

 

by: bukkoPosted on 2003-01-30 at 08:49:00ID: 7847001


...inside <% and %>, obviously!

bukko

 

by: gpyperPosted on 2003-01-30 at 09:26:48ID: 7847289

bukko that still produces the problem in the code as having the value appear as  "location.href='existingRecord.asp?str=<%" instead of just the ProductName.

 

by: webwomanPosted on 2003-01-30 at 09:54:18ID: 7847493

You can't use javascript in an option value.

ANd if all you want is the product name, get it from the database.

<option value="<%=objRS("ProductName")%>"
<%if request.querystring("str")=objRS("ProductName") then %>
selected
<%end if%>><%=objRS("ProductName")%></option>

Which should give you this output
<option value="product Name" selected>Product Name</option>

No javascript

Note: this is basically hongjun's answer, just formatted differently.

 

by: gpyperPosted on 2003-01-30 at 09:57:16ID: 7847517

webwoman

no that might populate the one dropdown but it does not allow the other checkboxes to be pupulated as a result of the selection

 

by: jitgangulyPosted on 2003-01-30 at 10:01:03ID: 7847543

>>jitganguly   The page just loops in a loading state
Whatd does that mean ?

I don't understand your question.

Do you want to go to a different URL based on an option value ?

Then use only the option value and on onchange use javascript

Please elaborate

 

by: gpyperPosted on 2003-01-30 at 10:29:08ID: 7847774

>>jitganguly  

The page kept reloading .... trhe url would flash in the address bar, page was blank and reload was almost instant. without having you see it thats the best I can describe it.

What I need to do is very simple. Same page (URL) is ok, loading back onitself is ok. I just want to get rid of the extra tex in the value tag of the option. And the code still has to work so theat the database populated pull down populates the checkboxes below.

 

by: gpyperPosted on 2003-01-30 at 11:08:57ID: 7848047

Bukko

tried your idea value still appears in the viewed source as <option value="location.href='existingRecord.asp?str=dBPFixedWireless'">dBPFixedWireless</option><

 

by: gpyperPosted on 2003-01-30 at 11:09:25ID: 7848053

Arrrrggg help this is driving me nuts

 

by: webwomanPosted on 2003-01-30 at 13:41:50ID: 7848982

You're mixing up client side and server side. You CANNOT put javascript in an option tag. Never will work.

The javascript should key off the selection of an option -- and that's TOTALLY client side. You use an ONCHANGE for that. CLIENT SIDE -- it has NOTHING to do with actually generating the option values.

What EXACTLY are you trying to do? If you want to go to another page when somebody picks an option, you're going about it COMPLETELY wrong.

 

by: gpyperPosted on 2003-01-30 at 13:56:20ID: 7849071

WebWoman

I'm not doing anything wrong the page works as it is. It functions fine, when I select a product from the dropdown the page reloads and I am presented with the subselections for that product. Everything is pulled from my database, take a look at the code in my first posting.

The problem is if you load up the page make the selection, then do a view source, the VALUE of the product displays as  "location.href='existingRecord.asp?str=productnamehere%> instead of just and only the product name. when the user is finished filling out the form I do not want the value to be the long string I only want to submit the product name.

 

by: gladxmlPosted on 2003-01-30 at 16:58:17ID: 7850039

gpyper,

As I understand it you want to get the value of the dropdown back into the database...

To get around this... I assume that the page is inside the form...

Since the option value is the location.href='existingRecord.asp?str=<%=objRS("ProductName")%>'"


Now put a hiddenfield and then paste here the vale of the request.querystring

<input type="hidden" name="hiddenField" value="request.querystring("str")">

When you pass the page later(saving into the db) you will just refer to the hiddenfield value and not the dropdown...


HTH...

Happy programming...


 

 

by: gladxmlPosted on 2003-01-30 at 17:07:12ID: 7850086

Reading thru the thread

>>>>>>
The problem is if you load up the page make the selection, then do a view source, the VALUE of the product displays as  "location.href='existingRecord.asp?str=productnamehere%> instead of just and only the product name. when the user is finished filling out the form I do not want the value to be the long string I only want to submit the product name.
>>>>>>


gpyper,

You dont need to do anything with the code

just add this one line of code and it will fixed the probelm...

<input type="hidden" name="hiddenField" value="request.querystring("str")">

HTH...

Happy programming...

 

by: jsaberonPosted on 2003-01-30 at 18:15:37ID: 7850341

gpyper, if your trying to load a page based on the selected product name then why not just submit the values?

<%
dim paramstr
dim prodname
paramstr = request.querystring("str")
%>

[....]

<form action="existingRecord.asp" method=get name=prodselect>
<select name="str" Class="form" onchange="javascript:document.prodselect.submit()">
<%
do while not objRS.EOF
  prodname = objRS("ProductName")
%>
<option value="<%=prodname%>'" <%if paramstr=prodname then%>SELECTED<%end if%>><%=prodname%></option>
<%
objRS.movenext
loop
%>
</select>
</form>

 

by: WakiePosted on 2003-01-30 at 19:45:06ID: 7850568

I agree, jsaberon.

 

by: gladxmlPosted on 2003-01-30 at 21:19:13ID: 7850968

gpyper,

The code looks familiar....

The method will be most helpful when you want a database dynamic dropdown... At the same time checking/validating using javascript when you hit submit...

That is why I dont use this method  document.prodselect.submit for such cases...

But the workaround that I've used for this is to put the real value of the dropdown into the hidden field...  

Just like I have mention on my prevoius post...


Regards,
Glad


 

by: rsashiPosted on 2003-01-30 at 22:20:21ID: 7851161

gpyper
have u solved ur problem

 

by: bukkoPosted on 2003-01-31 at 06:39:29ID: 7853350


gyper,

Looks to me like the code is doing exactly what you are asking.
If the value of objRS("ProductName") is "dBPFixedWireless", then this is working.

Maybe I don't understand the problem. What are you expecting to appear?
Whatever the problem it can be fixed.

Regards

bukko

 

by: bukkoPosted on 2003-01-31 at 06:40:48ID: 7853357


Do you want to get the page to resubmit to itself when the option is selected?

Regards

bukko

 

by: gpyperPosted on 2003-01-31 at 06:50:22ID: 7853426

Nice and simple solution, I like it when people don't try to complicate things.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...