Default value for combo box

D

Doogie

How do I make a value the default value for a combo box in ASP 3.0?
What I have below does NOT work, yet I've seen it in HTML file
examples before (and works if I put it in a HTML file by itself, but
not if I use it in a ASP 3.0 app.


<select name="cboCompany" style="text-align:right; font-size:8pt">
<option value="08">08</option>
<option value="09" selected="true">09</option>
<option value="33">33</option>
<option value="18">18</option>
<option value="17">17</option>
</select>
 
M

Mike Brind

Doogie said:
How do I make a value the default value for a combo box in ASP 3.0?
What I have below does NOT work, yet I've seen it in HTML file
examples before (and works if I put it in a HTML file by itself, but
not if I use it in a ASP 3.0 app.


<select name="cboCompany" style="text-align:right; font-size:8pt">
<option value="08">08</option>
<option value="09" selected="true">09</option>
<option value="33">33</option>
<option value="18">18</option>
<option value="17">17</option>
</select>

While the above is not valid html, it should work in most browsers, because
they appear to ignore what comes after "selected"

Valid in html 4.01 and below: <option value="09" selected>09</option>
Valid in xhtml: <option value="09" selected="selected">09</option>

What you tried should also work in most browsers in an ASP app, because all
asp does is render html. ASP is therefore not an issue.
 
D

Doogie

While the above is not valid html, it should work in most browsers, because
they appear to ignore what comes after "selected"

What is invalid about it? I want to make it valid so if it's invalid
please show me where.
Valid in html 4.01 and below: <option value="09" selected>09</option>
Valid in xhtml: <option value="09" selected="selected">09</option>

Neither of these work. I can create this combo box in a simple html
page and it works fine. But if I put it in an ASP 3.0 page, option 09
is not the default one. Option 08 (the first one) is. Is there some
other way - other than putting 09 first?
 
M

Mark J. McGinty

Doogie said:
What is invalid about it? I want to make it valid so if it's invalid
please show me where.


Neither of these work. I can create this combo box in a simple html
page and it works fine. But if I put it in an ASP 3.0 page, option 09
is not the default one. Option 08 (the first one) is. Is there some
other way - other than putting 09 first?

Did you view the HTML source as generated by your ASP script? I suspect it
is not generating exactly as you expect, because the browser doesn't care if
the markup is static or dynamic, as long as its correct.


-Mark
 
D

Doogie

Did you view the HTML source as generated by your ASP script? I suspect it
is not generating exactly as you expect, because the browser doesn't care if
the markup is static or dynamic, as long as its correct.

Bear with me, I'm a little new to the web dev world. But if you mean
did I do a "View source" on my asp page, I did and the HTML is as
listed above (and below). This is a brand new control on this page,
so there is no other code attached to it yet so I can't figure out why
it won't default to 09 like I'm being told it should.

The only thing else I can think of about this is that this combo box
is being added to a grid that is defined with XSL. The html below is
not part of the XSL, it's part of the HTML of the ASP page though. I
tried to add this code to that XSL too and it didn't change my
results.

<select name="cboCompany" style="text-align:right; font-size:8pt">
<option value="08">08</option>
<option value="09" selected="true">09</option>
<option value="33">33</option>
<option value="18">18</option>
<option value="17">17</option>
</select>
 
M

Mike Brind

Doogie said:
What is invalid about it? I want to make it valid so if it's invalid
please show me where.

The selected attribute in html 4.01 and below stands on its own In xhtml it
has to have the attribute and its value, hence selected="selected".
selected="true" does not exist in html or xhtml.
Neither of these work. I can create this combo box in a simple html
page and it works fine. But if I put it in an ASP 3.0 page, option 09
is not the default one. Option 08 (the first one) is. Is there some
other way - other than putting 09 first?

They both work in my tests, as they should. Why they don't for you is a
mystery. Please post the resulting source code from your page, and the
relevant lines of ASP that you use to generate the Select list html.

Incidentally, there is no such thing as a "combo box" in asp or html. ASP
is a technology that renders html on request according to the instructions
you give it in your code. The resulting html is then rendered by a browser
as best it can. Stricly speaking, this is not an ASP problem, it's an html
one.
 
D

Doogie

I switched it to "selected ="selected"" and that still does not work.
The "View Source" shows it as "selected="selected"" but the first
option - Company 08 - is the one that shows as the default. I've
tried it with just "selected" and that does not work either.

Here is the entire HTML for this one page. I'm not sure how much help
it will be because the app is many more pages than this and this
particular grid is loaded with some java script according to an xsl
file. But it shows that I clearly have it set the way I'm describing,
but it is not showing the default the way I need it to. Like I
mentioned, the html entry that I'm creating (cbocompany) is entirely
brand new, so there shouldn't be any code prohibiting it from using
the selected attribute as intended.


<HTML>
<HEAD>
<title>Create Adhoc Invoice</title>
<link REL="STYLESHEET" type="text/css" HREF="../CSS/CSXLines.css">
<script language="javascript" src="../includes/ReloadFooter.asp"></
script>
</HEAD>
<BODY onfocus=closePopUp() onload="ReloadFooter('Adhoc Invoice -
Create');" onkeypress="if(window.event.keyCode==13)
{btnDisplay.click()}">
<table cellspacing=1 cellpadding=0 border="0" width=610>
<tr>
<td width=250>
<fieldset>
<legend title="Search Criteria" style="font-size:8pt">Search
Criteria</legend>
<table width=100% border=0>
<tr>
<td class="small" align=right>Vendor:</td>
<td><span id=spnVendorScacs></span></td>
</tr>
<tr>
<td class="small" align=right>VendorTypes:</td>
<td><span id=spnVendorTypes></span></td>
</tr>
<tr>
<td class="small" align=right>Invoice Number:</td>
<td><input type=text id=txtInvoiceNumber style="font-size:8pt"
maxlength=20 onkeypress="toUpper()"></td>
</tr>
</table>
</fieldset>
</td>
<td width=20%>
<table>
<tr>
<td><input type=button name=btnDisplay value=Display style="width:
80px; font-size:8pt" onclick="GetAdhocInvoices()" id="Button1"></td>
</tr>
<tr>
<td><input type=button name=btnClear value=Clear style="width:
80px; font-size:8pt" onclick="ClearAll()"></td>
</tr>
<tr>
<td><input type=button name=btnAddVendor value="Add Vendor"
style="width:80px; font-size:8pt" onclick="AddVendor()"></td>
</tr>
</table>
</td>
<td>
<table height=90 align=right>
<tr>
<td><font face=verdana size=4><input type=button name=btnSave
value="Save Changes" style="width:80px; font-size:8pt;font-
face:verdana;" onclick="CallSaveChanges()"></font></td>
</tr>


<tr>
<td>
<font face=verdana size=4><input type=button name=btnComplete
value=Complete style=width:80px;font-size:8pt;font-face:verdana;
onclick=CallComplete()></font>
</td>
</tr>

</table>
</td>
</tr>
<tr>
<td align=center colspan=3>
<span id=spnTableDisplay oncontextmenu="AdhocRightClick(null);
return false" STYLE="overflow:auto; width:610px; height:170px;
position:relative; padding:0px; margin:0px; border-left:1px gray
solid; border-right:1px gray solid; border-top:1px gray solid; border-
bottom:1px gray solid"></span>
</td>
</tr>
<tr>
<td align=left>
<span id=spnAdhocDetails
oncontextmenu="AdhocDetailRightClick(null); return false"
STYLE="overflow:auto; width:340px; height:185px; position:relative;
padding:0px; margin:0px; border-left:1px gray solid; border-right:1px
gray solid; border-top:1px gray solid; border-bottom:1px gray solid"></
span>
</td>
<td align=right valign=top colspan=2>
<table>
<tr>
<td class="small" align=right>
Total Amount
</td>
</tr>
<tr>
<td>
<input type=text name=txtTotalAmount style="width:120px; font-
size:8pt; background-color:silver; text-align:right" readonly>
</td>
</tr>
<tr>
<td class="small" align=right>
Total Pay Amount
</td>
</tr>
<tr>
<td>
<input type=text name=txtTotalPayAmount style="width:120px; font-
size:8pt; background-color:silver; text-align:right" readonly>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align=center><span id=clientCallXML></span></td>
</tr>
<tr>
<td align=center><span id=returnXML></span></td>
</tr>
</table>

<span id=spnHidden style="visibility:hidden; overflow:auto; width:1px;
height:1px;">
<table><tbody id=spareDetailTable>
<tr align="center" style="font-family:verdana,arial; font-size:8pt;
background-color:white" onclick="onRowClick_singleSel(this,
'ADHOC_DETAIL')" oncontextmenu="AdhocDetailRightClick(this); return
false">
<td>
<input type="hidden" name="hdn_ItemID">
<input type="text" name="txt_ItemDS" size="20" readonly=""
style="font-size:8pt">
</td>
<td align="right">
<input type="text" name="txt_ItemQT"
onkeypress="filterNonNumeric()" maxlength="4" size="6" style="text-
align:right; font-size:8pt" >
</td>
<td align="right">
<input type="text" name="txt_ItemAM" value="$0.00"
onblur="checkCurrency(this); recalcTotal()" maxlength="10" size="12"
style="text-align:right; font-size:8pt">
</td>
</tr>
<tr align="center" style="font-family:verdana,arial; font-size:8pt;
background-color:white; height:30">
<td></td>
<td class="small" align="right">Total Amount:</td>
<td class="small" align="right">$0.00</td>
</tr>
</tbody></table>
<table><tbody id=spareInvoiceTable>
<tr align="center" style="font-family:verdana,arial; font-size:8pt;
background-color:white" onclick="AdhocInvoiceSelected(this)"
oncontextmenu="AdhocRightClick(this); return false">
<td>
<input type="hidden" name="hdn_MATCH_FL">
<input type="hidden" name="hdn_totalAmount" value="EMPTY">
<input type="hidden" name="hdn_status" value="insert">
<input type="hidden" name="hdn_detailStatus" value="clean">
<input type="hidden" name="hdn_SCAC_CD">
<input type="hidden" name="hdn_company_id" value="">
<input type="text" name="txt_SCAC_AN" readonly="" size="10"
style="background-color:silver; font-size:8pt">
<input type="hidden" name="hdn_Appr_id" value="EMPTY">
</td>
<td>
<input type="text" name="txt_INVOICE_NUMBER_AN" size="10"
maxlength="20" style="font-size:8pt"
onchange="checkInvoiceNumber(this)" onblur="if(!
this.readOnly)checkInvoiceNumber(this)" onkeypress="toUpper()">
</td>
<td>
<input type="text" name="txt_VENDOR_TYPE_AN" readonly="" size="5"
style="background-color:silver;text-align:center; font-size:8pt">
</td>
<td>
<input type="text" name="txt_ACCOUNTING_CD" readonly="" size="10"
style="background-color:silver; font-size:8pt">
</td>
<td>
<input type="text" name="txt_INVOICE_DT" onBlur="checkdate(this)"
size="11" maxlength="11" style="font-size:8pt">
</td>
<td>
<input type="text" name="txt_ACCRUAL_DT" onBlur="checkdate(this)"
size="11" maxlength="11" style="font-size:8pt">
</td>
<td>
<input type="text" name="txt_BEGIN_BILLING_DT"
onBlur="checkdate(this)" size="11" maxlength="11" style="font-size:
8pt">
</td>
<td>
<input type="text" name="txt_END_BILLING_DT"
onBlur="checkdate(this)" size="11" maxlength="11" style="font-size:
8pt">
</td>
<td>
<input type="text" name="txt_AP_SENT_DT" onBlur="checkdate(this)"
size="11" maxlength="11" readonly="" style="background-color:silver;
font-size:8pt">
</td>
<td>
<input type="text" name="txt_AP_RECEIVED_DT"
onBlur="checkdate(this)" size="11" maxlength="11" readonly=""
style="background-color:silver; font-size:8pt">
</td>
<td>
<input type="text" name="txt_IP10_AN" size="5" maxlength="3"
style="font-size:8pt">
</td>
<!--h0448-->
<td>
<!--<input type="text" name="txt_SERVICE_SN"
onkeypress="filterNonNumeric()" size="5" maxlength="3" style="text-
align:right; font-size:8pt">-->
<select name="txt_SERVICE_SN" style="text-align:right; font-size:
8pt">
<option value="23">23</option>
<option value="60">60</option>
<option value="14">14</option>
<option value="18">18</option>
<option value="17">17</option>
</select>
</td>
<!--h0448-->
<td>
<select name="cboCompany" style="text-align:right; font-size:8pt">
<option value="08">08</option>
<option value="09" selected="selected">09</option>
<option value="33">33</option>
<option value="18">18</option>
<option value="17">17</option>
</select>
</td>
<td>
<input type="checkbox" name="chkBxTaxable"
onclick="taxableClicked(this)">
</td>
<td>
<a class="small" href="javascript:selectTaxName()"
id="a_TAX_NAME_DS">NULL</a>
<input type="hidden" name="txt_TAX_ID">
</td>
<td>
<input type="text" name="txt_COMMENT_DS" size="15" maxlength="132"
style="font-size:8pt">
</td>
</tr>
</tbody></table>
</span>
<script>

</BODY>
</HTML>
 
M

Mike Brind

Doogie said:
I switched it to "selected ="selected"" and that still does not work.
The "View Source" shows it as "selected="selected"" but the first
option - Company 08 - is the one that shows as the default. I've
tried it with just "selected" and that does not work either.

Here is the entire HTML for this one page. I'm not sure how much help
it will be because the app is many more pages than this and this
particular grid is loaded with some java script according to an xsl
file. But it shows that I clearly have it set the way I'm describing,
but it is not showing the default the way I need it to. Like I
mentioned, the html entry that I'm creating (cbocompany) is entirely
brand new, so there shouldn't be any code prohibiting it from using
the selected attribute as intended.

The html is useless without the js files. It doesn't show anything on its
own. One thing though, when I loaded it into Dreamweaver, the codeview
through a fit. The reason for that is that your html is so full of errors
that it couldn't cope, and colour-coded everything wrong. This is
definitely NOT an asp problem. Run your page through an html validator and
fix all the errors. That will, IMO, fix your problem.

If you need help with that, try an html group.
 
D

Doogie

I appreciate your help (everyones). But I'm not sure how much time I
am going to be allowed to do anything other than try to get the combo
box to default as I explained above. I'm new and this app is an old
app and it's ASP 3.0 which means its old technology too. My
experience before coming here is more in back-end development and so I
may have to ask someone else to try to tackle why what should be a
simple change isn't working because I just don't get it. Thanks
though again. Doug
 
M

Mike Brind

Doogie said:
I appreciate your help (everyones). But I'm not sure how much time I
am going to be allowed to do anything other than try to get the combo
box to default as I explained above. I'm new and this app is an old
app and it's ASP 3.0 which means its old technology too. My
experience before coming here is more in back-end development and so I
may have to ask someone else to try to tackle why what should be a
simple change isn't working because I just don't get it. Thanks
though again. Doug

As I said, it's simple: for html to render correctly in a browser, it has to
be correct. The resulting html in your page is not. I suspect that the
errors further up the page are what is preventing the select list from
showing up as you expect. If you take that part of the html out and paste
it on its own in a page, it works. If you put the select list much firther
up your page, it will probably work, because it won't be "infected" by
preceding bad html. Fix the errors, then it will work. That's all anyone
here can suggest. Ignore the fact that you are using ASP. That's a red
herring.
 
M

Mark J. McGinty

Doogie said:
I appreciate your help (everyones). But I'm not sure how much time I
am going to be allowed to do anything other than try to get the combo
box to default as I explained above. I'm new and this app is an old
app and it's ASP 3.0 which means its old technology too. My
experience before coming here is more in back-end development and so I
may have to ask someone else to try to tackle why what should be a
simple change isn't working because I just don't get it. Thanks
though again. Doug

You are surely free to do that... main drawback to that plan is that you
still seem to believe ASP has something to do with this problem. Since
that, in fact, is not the case, you've saddled yourself with a distinct
disadvantage. It's very difficult (if not impossible) to make any progress
while persistently asking the wrong questions.

Typically, I avoid definitive statements like the one above... I've been
programming professionally going on 20 years, I worked on the DoD contract
project that delivered the very first Windows App created for the US Army...
over the years I've witnessed any number of things that were amazingly
anomalous, entirely inexplicable and/or *highly* improbable by definition.
Experience leaves me hesitant to say that anything in IT specifically could
or couldn't be, especially sight unseen... usually... anyway...

Out of curiosity I copied the html source you posted to a local html file.
There was an unclosed script tag near the bottom, but after I fixed that,
the page rendered. I fully expected to see '09' in that SELECT element, but
to my surprise, I didn't see the SELECT element at all. I knew it was in
the source, though, so I used a tool I wrote (www.pagespy.com) to look for
it.

As it turns out, the SELECT element is contained by a SPAN that is hidden in
two ways. (style.visibility = 'hidden', and style.width/style.height both
set to 1px.) I used pagespy's script context to change those styles/reveal
the element in question -- predictably, the initial value of the SELECT
element was '09'. Surprised me not at all.

The exercise would be pointless, but I can guarantee you that if I renamed
this file .asp and copied it to my local web root, it would render the same
'09', just as we all know it's supposed to. Test concluded.


Ok, so exactly what, if anything, does all this prove? (And, as long as
we're asking rhetorical questions, how could it possibly justify all the
rambling-on you see above?) Very astute of you to ask, I'll tell you:

1. You aren't able to see the SELECT element in question immediately after
the page renders -- if you were you would've seen that the selected
attribute does/did work.
2. By the time you *are* able to *actually* see it, some client-side script
has already been executed in response some UI interaction.
3. Said client-side script clearly concerns itself with the SELECT in
question (and its other initially-hidden SPAN-dweller siblings.)
4. You purposely omitted from your post some client script that was present
in the source dump -- what else explains the unclosed SCRIPT tag (presence
of which prevents the page from rendering in the least tiny way)? (I won't
even ask why.)
5. Without all of the page's client script, impossible for me to quote-back
the line of it that's responsible, but regardless, there is NOT A DOUBT in
my mind that's what is happening...
6. Client script -- not ASP -- is changing the selected option, before it
lets you see it.


If you still have any doubts, disable Active Script in IE security, change
the code so that can see the element you've been on about for days...
observe... and then post an accurate description of how this experience made
you feel.


Good Luck,
Mark
 
D

Doogie

There was an unclosed script tag near the bottom, but after I fixed that, the page rendered.

I apologize about that, I did pull the javascript out of the code
because I am not all that sure how much I should be posting of this
code. It's not that it's overly secure or anything but I just wanted
to be careful and wasn't sure if there was anything in there that was
secure.
As it turns out, the SELECT element is contained by a SPAN that is hidden in two ways. (style.visibility = 'hidden', and style.width/style.height both set to 1px.) I >used pagespy's script context to change those styles/reveal the element in question -- predictably, the initial value of the SELECT element was '09'. Surprised me not >at all.

I did that too after you suggested it - thank you. But it doesn't
really solve my problem. See, the grid this select element is in is
hidden until the user tries to add a new invoice. At that point it
shows up (all of this I believe you touch on in your 6 points). If I
remove the hidden settings, then the grid shows up (and not even in
the right place). But I think you have at least pointed me down the
right path, where now I know where to work in order to get this to
work properly.

I agree now with everyone who has said from the beginning that this
isn't an ASP problem.
and then post an accurate description of how this experience made you feel.
From the beginning I've felt like I'm right out of college again where
nothing makes sense to me yet. :)

Again, thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top