I am new to classic ASP. What is wrong with the code below: If condition error, don't get it. Please help.
<select NAME="Priority" style="WIDTH:200px" Id="Priority">
<option value='0' <%= if(condition) then "selected" end%> 0 </option>
<option value='1' <%= if(condition) then "selected" end%> 1 </option>
<option value='2' <%= if(condition) then "selected" end%> 2 </option>
<option value='3' <%= if(condition) then "selected" end%> 3 </option>
</select>
Should be :
<% if condition then response.write("selected") %>
For more info see here:
http://www.codefixer.com/tutorials/If_then_else.asp
There is no in-line if function (note I didn't say statement) in VBScript. So I always have this in my toolbox:
function iif(siONo, SiRetval, NoRetval )
if SiONo then
iif = SiRetval
else
iif = NoRetval
end if
end function
Which allows you to do:
<option value='0' <%= iif(condition, "selected", "") %> 0 </option>
If the select (Priority) is getting its data from a database then you could use a function.
Is the page updating or inserting?
<select NAME="Priority" style="WIDTH:200px" Id="Priority">
<option value="0" <%= isSelected(Priority,"0") %>>0</option>
<option value="1" <%= isSelected(Priority,"1") %>>1</option>
<option value="2" <%= isSelected(Priority,"2") %>>2</option>
<option value="3" <%= isSelected(Priority,"3") %>>3</option>
</select>
Function isSelected(x,y)
if Cstr(x) = Cstr(y) then
isSelected = "selected=""Selected"""
else
isSelected = ""
end if
end Function
The item Priority would be a numeric field and have a default value assigned. Place the function snippet in a page that is used globally.
You were missing if in 'end if' and there was a extra closing tag missing in after closing asp code block %>. Hope this works.
<select NAME="Priority" style="WIDTH:200px" Id="Priority">
<option value="0" <% if(condition) then Response.write("selected") end if %>>0</option>
<option value="1" <% if(condition) then Response.write("selected") end if %>>1</option>
<option value="2" <% if(condition) then Response.write("selected") end if %>>2</option>
<option value="3" <% if(condition) then Response.write("selected") end if %>>3</option>
</select>
Related
I have a select box that runs a small method on each option to determine what 'selected' is:
<label for="soft-due-date-controller">Soft Due Days:</label>
<select class="form-control" id="soft-due-date-controller">
<option value="0" {{determineDefaultSelect '0'}}>0</option>
<option value="1" {{determineDefaultSelect '1'}}>1</option>
<option value="2" {{determineDefaultSelect '2'}}>2</option>
<option value="3" {{determineDefaultSelect '3'}}>3</option>
<option value="4" {{determineDefaultSelect '4'}}>4</option>
<option value="5" {{determineDefaultSelect '5'}}>5</option>
<option value="6" {{determineDefaultSelect '6'}}>6</option>
<option value="7" {{determineDefaultSelect '7'}}>7</option>
<option value="8" {{determineDefaultSelect '8'}}>8</option>
<option value="9" {{determineDefaultSelect '9'}}>9</option>
<option value="10" {{determineDefaultSelect '10'}}>10</option>
</select>
Here is the method:
determineDefaultSelect: function(optionText){
let savedSoftSchedueDays = SoftDueDates.find().fetch()[0].currentSoftMargin;
if(optionText == savedSoftSchedueDays){
return "selected";
}
},
On the client side... it ends up loading appropriately and responsively updates in the dropdown when I update the db directly. My problem is that I am getting the following error on load multiple times on load:
Exception in template helper: TypeError: Cannot read property 'currentSoftMargin' of undefined
While it works, this error does not seem right and this is the only place in the code where currentSoftMargin is used. Almost like the template helper determineDefaultSelect is running faster than the db call can happen and a product async calls... maybe? Can I prevent this?
You're getting this error when the helper runs before the subscription to your data is ready(). You can either wait for the subscription is ready to render the template (rendering a spinner in the meantime instead) or defend against the runtime error:
determineDefaultSelect: function(optionText){
const doc = SoftDueDates.findOne(); // equivalent to .find().fetch()[0];
const savedSoftScheduleDays = doc && doc.currentSoftMargin; // will not error
return (optionText == savedSoftScheduleDays) ? "selected" : ""; // shorthand
},
Use {{#if Template.subscriptionsReady}}{{/if}} in your template to ensure all the data needed are ready.
I use #Html.EditorFor(model=> model.Score) in my "create" view but I would like to write
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
but how do I connect the select I write with the model.Score ???
You should use DropDownListFor instead of EditorFor.
In your case it could be:
#Html.DropDownListFor(m => m.SelectedScore, Model.PossibleScores)
where names are self-described.
An example of usage
I have this ASP on the form page
<select id="per_pre_6" name="per_pre_6">
<% for i=0 to 100 %>
<option value="<%=i %>" <%if i=rs("per_pre_6_score") then %>selected="selected" <%end if %>><%=i %></option>
<%next %>
</select>
The HTML (cut down version) looks like this
<select id="per_pre_6" name="per_pre_6">
<option value="0" >0</option>
<option value="1" >1</option>
...
<option value="99" >99</option>
<option value="100" selected="selected" >100</option>
</select>
So far so good. I then choose another value other than 100 e.g. 90 and I submit the form. On the resulting page I have the following
per_pre_6= CleanSQL(Request.Form("per_pre_6"))
response.Write("("&per_pre_6&")")
For some reason, it's showing 100 and not the value I chose. Any reason why?
So I submitted the form and the new value was submitted, which was nice, however when I run it again with the new value being the one that's selected and I choose a new value, 100 is still being shown!
Make sure to have method="post":
<form action="handleFormData.asp" method="post">
If you want to use Request.Form
Edit:
If its due to caching, try:
Respose.Buffer = True
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
I've can't seem to find a solution to this so I'm posting here.
Basically I'm trying to build a basic filter for property listings. All the property listings are just posts with custom fields. For example, one of the properties has these values in the custom fields:
custom field value
------------ -----
area 150
rooms 4
bathrooms 2
garage 1
alfresco 1
study 1
theatre 1
My search form HTML looks like this:
<form method="get" id="advanced_search" action="<?php echo get_settings('home'); ?>/" >
<fieldset>
<label>Rooms
<select name="rooms">
<option value="">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</label>
<label>Bathrooms
<select name="bathrooms">
<option value="">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</label>
<label>Garage
<select name="garage">
<option value="">Any</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</label>
<label>Area (square metres)
<select name="garage">
<option value="">Any</option>
<option value="100">100</option>
<option value="150">150</option>
<option value="200">200</option>
<option value="250">250</option>
</select>
</label>
<label><input type="checkbox" name="theatre" value="1" /><span>Home Theatre</span></label>
<label><input type="checkbox" name="study" value="1" /><span>Study</span></label>
<label><input type="checkbox" name="alfresco" value="1" /><span>Alfresco</span></label>
<input type="submit" id="submit" value="Search" />
</fieldset>
</form>
What I am wanting to do is let the user use this filter to only show posts on a search results page that match it.
There's a slight catch too: all these custom field represents a minimum value. So if they selected "200" from "Area", "1" from "Alfresco", then it needs to show all properties that are 200 and higher and have at least 1 Alfresco area.
And - I'd like to limit the search filter to just the category called "properties".
Not asking much? :-P
Any help would be appreciated.
I ran into a strange problem with checkbox groups. I am trying to get the values from a group of checkboxes, but I have to hit the submit button twice for it to get the values... I have no idea why. I also use a dropdown box on the same form and I only need to hit the button once to get its value.
my asp code to write it to page
Dim selectFormValue
selectFormValue = Replace(Request.Form("selectTest"), """", "")
Response.write Request.Form("checkGroup")
here is the html being generated
<form method="post" name="formTest">
<select name="selectTest">
<option value='123"' selected="">Option 1</option>
<option value='124"' selected="">Option 2</option>
<option value='125"' selected="">Option 3</option>
</select>
<input type="checkbox" name="checkGroup" value="1" CHECKED />
<input type="checkbox" name="checkGroup" value="2" CHECKED />
<input type="checkbox" name="checkGroup" value="3" CHECKED />
<input type="checkbox" name="checkGroup" value="4" CHECKED />
<input type="submit" name="submit" value="Update" />
</form>
Thanks!
One thing i note is, that you don't specify an action in your form.