|
-
Jun 20th, 2001, 08:37 AM
#1
Thread Starter
Addicted Member
Adding elements to SELECT with VBScript ?
How can I add elements to SELECT with VBScript ?
Thanks !
-
Jun 20th, 2001, 10:01 AM
#2
Black Cat
You refering to HTML form tags or SQL queries???
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jun 20th, 2001, 10:04 AM
#3
Thread Starter
Addicted Member
Ok, my fault; I wasn't explicit enough.
It may sound dumb but just plain HTML, how can I add dynamically element to SELECT ?
Thanks
-
Jun 20th, 2001, 10:54 AM
#4
Frenzied Member
[2nd Attempt to Post]
What, are Josh, Monte, and me the only ones working this forum?
Nino, you can build an loop and write your options.
Code:
<select name='mySelect'>
<%
for i = 0 to UBound(MyOptions, 1)
%>
<option value='<%=MyOptions(0, i)%>'><%=MyOptions(1, i)%></option>
<%
next 'i
%>
</select>
'Course, there are a dozen different ways I could've done that: not use an array, use Response.Write to cut down on the <% %>, yadda yadda
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 20th, 2001, 11:08 AM
#5
Thread Starter
Addicted Member
Thank you Ciberthug, but that's not what i was looking for;
I figured out how to do that in asp, but if the users decides to add an element to existing options I enumerate in asp ?
This is in a form to add a new record to our db.
It's working well, but since there are no combobox in HTML, i choose to use textboxes in conjunction with listbox (synchronized). needless to say, my boss didn't like it as much as I did lol.
So he asked me to redesign the form w/o textboxes and just buttons instead where the user should click and then an inputbox would ask them what they would like to add...
I just need the part where in vb i would have done this :
cboItems.additem "MyNewItem"
cboItems.Text = "MyNewItem"
Thanks !
-
Jun 20th, 2001, 04:28 PM
#6
Frenzied Member
Pretty much the same in VBScript except the [] are () and you don't need the ; at the end of the line.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Jun 20th, 2001, 04:38 PM
#7
Frenzied Member
I think for VBScript it is something like this:
Code:
<script language=VBScript>
Sub addNew
Dim objOption
Set objOption = document.createElement("OPTION");
objOption.innerText = 'Whatever'
objOption.value = '5'
myForm.mySelect.options.add(objOption)
Set objOption = Nothing
End Sub
</script>
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Jun 21st, 2001, 11:02 AM
#8
Thread Starter
Addicted Member
Ok thanks for the reply, but have you tried your script ?
It's not working.
I can't mix Vbscript & javascript so I'll find another way I guess... !
Thanks for the reply again !
-
Jun 21st, 2001, 11:14 AM
#9
Frenzied Member
Who's script, mine or Monte's? I told you mine was off.
But what do you mean you can't mix VBScript and JavaScript? They can't be in the same script tag, but... I didn't realize they couldn't be on the same page.
I would check on that, but I don't ever use VBScirpt for client-side, so I don't care. I use VBScript for the ASP server-side and JavaScript for the client-side.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 21st, 2001, 11:25 AM
#10
Thread Starter
Addicted Member
Monte's script.
I'm sorry for the misunderstanding; when I said I couldn't mix VBScript and javascript, I meant that I thought Vbscript couldn't call a function in javascript... Am I wrong ?
Anyway, I found a solution, I used another way w/o adding options !
Thanks anyway guys !
VBWorld is the best place on the web !
-
Jun 21st, 2001, 11:54 AM
#11
Frenzied Member
Oh, no, you are right. VBScript couldn't call a JavaScript function and vice versa. They would pretty much run as two seperate programs with their own memory space ontop of the page. They could access the same page elements, though, but not each other.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 22nd, 2001, 12:06 AM
#12
Frenzied Member
I was doing that from the top (or maybe the bottom?) of my head.. didn't bother to test it... should have gotten you close though....
like:
Code:
<script language=VBScript>
Sub addNew
Dim objOption
Set objOption = document.createElement("OPTION");
myForm.mySelect.options.add(objOption)
//Assuming your form is named myForm and your select
//is named mySelect
objOption.innerText = 'Whatever'
objOption.value = '5'
Set objOption = Nothing
End Sub
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Jun 22nd, 2001, 12:43 AM
#13
Thread Starter
Addicted Member
Hehe monte's I'm not that dumb, Yet ( )
I modified your script but couldn't get it to work, plus you forgot the Sub() and left javascript's ";" 
Thanks anyway !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|