• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

get default values

I've got this problem with setting default values in a form.
i get values from asp1 in asp2.now these values are stored in variables and they should be the default values of a textbox,listbox(<select> html),radio buttons,check boxes.
I'm able to do for textboxes but what happens in the others.
I don't want a solution in javascript but in vbscript.Please let me know as early as possible.thanx.
  • 2
  • 2
1 Solution
For List boxes:
Suppose the the list box is as follows,
<SELECT NAME="purchase" SIZE="5">
<OPTION VALUE="TP">Toilet paper

then to set default values,(assuming the variable in which you stored it's value is 'var')
<OPTION <% if var="Soap" then response.write "selected"%>>Soap
<OPTION VALUE="TP" <% if var="TP" then response.write "selected"%>>Toilet paper
<OPTION <% if var="Cereal" then response.write "selected"%>>Cereal
<OPTION <% if var="Bread" then response.write "selected"%>>Bread
<OPTION <% if var="Milk" then response.write "selected"%>>Milk
<OPTION <% if var="Butter" then response.write "selected"%>>Butter

Similarly for a check box and Radio button (again assuming it's value stored in variable 'var')
<INPUT TYPE="checkbox" NAME="donation" <% if var="on" then response.write "CHECKED" %> >
<INPUT TYPE="radio" NAME="somecheck" <% if var="on" then response.write "CHECKED" %> >
rvsamuelAuthor Commented:
i'll try it and reply back.thanx anyway.
rvsamuelAuthor Commented:
u'r code works perfectly thanx.what'll happen if i have my <option> tag inside a loop and try to assign values from an array .Pls reply back.
Yes, certainly you can do it. But it'll be very good solution only when you have many items in the list.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now