problems populating form data from database

gpyper
gpyper used Ask the Experts™
on
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
%>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Do this then
<option value='<%=objRS("ProductName")%>' <%if request.querystring("str")=objRS("ProductName") then response.write "selected" end if%>><%=objRS("ProductName")%></option>


hongjun
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



Author

Commented:
no that code does not work

, If you look the other field is being populated based on the initial product selection
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Author

Commented:
sorry last was aimed at hongjun

Author

Commented:
jitganguly   The page just loops in a loading state

Commented:

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
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!

Commented:

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

bukko

Author

Commented:
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.

Commented:
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.

Author

Commented:
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
>>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

Author

Commented:
>>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.

Author

Commented:
Bukko

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

Author

Commented:
Arrrrggg help this is driving me nuts

Commented:
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.

Author

Commented:
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.

Commented:
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...


 

Commented:
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...

Commented:
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>

Commented:
I agree, jsaberon.

Commented:
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


Sashi RachabattulaSCRUM Master, Technical Manager

Commented:
gpyper
have u solved ur problem

Commented:

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

Commented:

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

Regards

bukko

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial