DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Discuss "Textbox or List help" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Closed Thread « Previous Thread | Next Thread »  
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old April 18th, 2008, 03:59 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 157
Thanks: 29
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Exclamation Textbox or List help

Hi All,

I need help with the following, I get an "Object Expected" error when page is loaded and it doesn't load the textbox, when I have the lines that I have commented out, it seems to work but continue to get the error if I try to pull in the recordset.

Code:
objectType = 0;
function changeFormObject() {
    var object_span = "";
    var change_span = "";
    if (objectType != 1) {
        object_span += ("<input type='text' name='PartNum' />");
        change_span += ("Pick from List!");
        objectType = 1;
    }
    else {
        object_span += ("<select name='PartNum'>");
        object_span += ("<option value=''> - SELECT - </option>");
 
            <%
            'strSQL = "Select PartNum from vwPartNumbers"
                       'set rs = conn.execute(strSQL)
            'Do while not rs.eof
            '    response.write ("object_span += ""<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>""")
            '    rs.movenext
            'Loop            %>
 
        object_span += ("</select>");
        change_span += ("change to textbox.");
        objectType = 2;
    }
    document.getElementById("object_span").innerHTML = object_span;
    document.getElementById("change_span").innerHTML = change_span;
}
Code:
<BODY onload="changeFormObject()">
<TR>
    <TD>Part Number:</TD><TD><span id="object_span"></span>&nbsp;&nbsp;<span id="change_span" onclick="changeFormObject()" onmouseover="this.style.cursor='pointer';"></span>
    </TD>
    </TR>

Last edited by richyrich; May 6th, 2008 at 12:00 PM. Reason: Removed [SOLVED] from title
Sponsored Links
  #2 (permalink)  
Old April 18th, 2008, 05:03 PM
Wolffy's Avatar
Slaprentice of Wolves


 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 146
Thanks: 1
Thanked 23 Times in 20 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

This line looks queer:
response.write ("object_span += ""<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>""")

shouldn't the += be outside the quotes?
  #3 (permalink)  
Old April 18th, 2008, 10:16 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 157
Thanks: 29
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

queer...hehe

ok, i tried this but get syntax error on the = sign. Is this what you mean?

Code:
response.write (object_span += ""<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>"")
  #4 (permalink)  
Old April 19th, 2008, 10:44 AM
Wolffy's Avatar
Slaprentice of Wolves


 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 146
Thanks: 1
Thanked 23 Times in 20 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

I admit, I took a quick look at it before leaving yesterday. Lemme look it over again when I get a chence if no one else jumps in.

[EDIT]
OK, it looks like you are attempting to build the HTML for a select tag into the variable object_span. If so, then I wonder about the response.write in your while loop. Wouldn't that cause your option tags to be written out before the select tag that contains them? If I'm on the right track, then I think the line in your loop should be just:

object_span += "<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>"

The HTML for the select is written out later in your snippet
document.getElementById("object_span").innerHTML = object_span;

Not sure if this solved the Object Expected error, but it should do something different at least.

Or was the Response.write for debugging purposes -- if so I'm on the wrong track here.

Last edited by Wolffy; April 19th, 2008 at 01:10 PM.
  #5 (permalink)  
Old April 20th, 2008, 06:16 AM
richyrich's Avatar
Moderator

 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 320
Thanks: 22
Thanked 23 Times in 23 Posts
Rep Power: 1
richyrich is on a distinguished road

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Try changing this line:-
Code:
response.write ("object_span += ""<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>""") 

to:-
Code:
response.write (vbcrlf&"object_span += ""<option value='" & rs("PartNum") & "'>" & rs("PartNum") & "</option>""") 

Last edited by richyrich; April 20th, 2008 at 06:48 AM.
  #6 (permalink)  
Old April 20th, 2008, 09:16 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 157
Thanks: 29
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

Thanks Wolffy and Richyrich for the reply.

The solution Richyrich provided seem to be the trick. It is working, just seems a little slow.

I have to work on the select statement now because it seems like I'm getting some weird results but that's something different.

Do you guys know if this is how you would pull the data for the list? I'm just wondering if there is another way to still get the same results.

I'm going to be attempting to allow either to enter thru the textbox or when a selection is made thru the list, it will populate some of the other fields.

Cheers!
  #7 (permalink)  
Old April 21st, 2008, 03:50 AM
richyrich's Avatar
Moderator

 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 320
Thanks: 22
Thanked 23 Times in 23 Posts
Rep Power: 1
richyrich is on a distinguished road

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Personally, I tend to render the dropdown to the page as normal and use visibility and display styles to hide / show it.

Do you mean the speed of the JS change or the speed of the page load?

If it's the JS change, maybe try the visibility/display solution.

Something like:-
Code:
<select id="PartNum" name="PartNum" style="display:none;visibility:hidden;">
 
Then in JS
document.getElementById('PartNum').style.display='block';
document.getElementById('PartNum').style.visibility='visible';
Hope that helps.
  #8 (permalink)  
Old April 21st, 2008, 07:38 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 530
Thanks: 14
Thanked 38 Times in 37 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead is on a distinguished road

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

@rr - why not just display:none? I'm confused on why both style attributes would be needed. From what I understand, display:none does not render the HTML to the page. visibility:hidden will make the element not visible, but it still occupies the same space. But it wouldn't appear that would be needed if display:none is set.
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
  #9 (permalink)  
Old April 21st, 2008, 09:28 AM
richyrich's Avatar
Moderator

 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 320
Thanks: 22
Thanked 23 Times in 23 Posts
Rep Power: 1
richyrich is on a distinguished road

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I think I had cross browser problems in the past just using visibility, so force of habit I use both....

I think in FF an item with visibility:hidden doesn't use up space, whereas in IE, it does.

It just stems from problems I had in the past, but yes, you could just use visibility....

Was just giving both options...
  #10 (permalink)  
Old April 21st, 2008, 10:00 AM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 157
Thanks: 29
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

Hi Richyrich,

It's slow when I click on "Pick from List". I'll check out your suggestion. Thanks!
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/javascript-programming/136-textbox-list-help.html
Posted By For Type Date
Textbox or List help - JavaScript Programming This thread Refback April 18th, 2008 08:23 PM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 07:43 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46