Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inStr Problem 1

Status
Not open for further replies.

PhatH

IS-IT--Management
Mar 30, 2004
88
US
I'm trying to check particular box(es) with ProdTypeName that have ProdTypeID/s which match a prodtypeid string that contains one or more ProdTypeID number ex: 1, 2, 3,...

<%
sql = "SELECT * FROM tblProductType"
Set rs1 = objConn.Execute(sql)
do while not rs1.eof
%>
<input type="checkbox" value=<% =rs1("ProdTypeID") %> name="prodtypeid" <% if inStr(prodtypeid,"<% =rs1("ProdTypeID") %>") then response.write ("Checked") %>><% =rs1("ProdTypeName") %>
<%
rs1.MoveNext
Loop
%>

The code is not right... could you tell...
 
your script delimiters are messed up in this

Code:
<input type="checkbox" value=<% =rs1("ProdTypeID") %> name="prodtypeid" <% if inStr(prodtypeid,"<% =rs1("ProdTypeID")[red] %>") [/red]then response.write ("Checked") %>><% =rs1("ProdTypeName") %>

use
Code:
with response
    .write "<input type='checkbox' name='prodtypeid' value='"
    .write rs1.fields("ProdTypeID") & "'"
if inStr(prodtypeid,rs1("ProdTypeID") = 0 then
    .write " checked"
end if
    .write ">"
    .write rs1("ProdTypeName")
end with

not tested the above code btw



Chris.

Indifference will be the downfall of mankind, but who cares?
 
PhatH. I use a very simple function that I call to set checkboxes and select lists appropriately. The function looks like this. You can place this function anywhere on the current page. I put mine in my general INCLUDE file that appears on every page in my app.

Code:
Function checkVal(val1,val2,returnStr)
  checkVal = ""
  IF val1 = val2 THEN
    checkVal = returnStr
  END IF
End Function

Then in my pages, I would write your code like this.
Code:
<%
dim v1

sql = "SELECT * FROM tblProductType"
Set rs1 = objConn.Execute(sql)

do while not rs1.eof
  v1 = 0
  IF inStr(prodtypeid,rs1("ProdTypeID")) > 0 THEN
    v1 = 1
  END IF
%>

<input <%=checkVal(v1,1,"checked")%> type="checkbox" name="[i]name[/i]">

<%
  rs1.MoveNext
Loop
%>

Basically what's happening here is you are passing two values to be examined by the checkVal function. If they are equal to each other, checkVal returns the string function you designate in the 3rd parameter of the function call. Otherwise, as you can see in the function, it returns an empty string. I like this function because it works the same for a select list also. Something like this.

Code:
<select name="[i]name[/i]">
<%
dim v1

sql = "SELECT * FROM tblProductType"
Set rs1 = objConn.Execute(sql)

do while not rs1.eof
  v1 = 0
  IF inStr(prodtypeid,rs1("ProdTypeID")) > 0 THEN
    v1 = 1
  END IF
%>

<option <%=checkVal(v1,1,"selected")%> value="[i]value[/i]">[i]Text[/i]</option>
<%
  rs1.MoveNext
Loop
%>
</select>

The same function works for select lists as well. I just pass the 3rd parameter as the string "selected" instead of "checked".

Hope this helps.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top