|
-
May 17th, 2001, 03:44 AM
#1
Thread Starter
Frenzied Member
Select Element Question
I'm using a select element on my html page.
Lets say its called cboPriority.
How do I move the value of this element into a temporary field ? I want to store the text that is displayed on screen for the user, not the index number or anything like that.
I tried using the 'VALUE' attribute, but that always appears empty.
TIA.
-
May 17th, 2001, 04:08 AM
#2
Lively Member
Ok, so you want to move the text from a select-box to another field?
Code:
<html><body>
<form name="frm">
<select name="sel">
<option value="1">VB</option>
<option value="2">ASP</option>
</select>
<br>
<input type="button" onClick="document.frm.txtVal.value=document.frm.sel[document.frm.sel.selectedIndex].text">
<input type="text" name="txtVal">
</form></body></html>
When you click the button, the text from the select-box will be displayed in the text-box. This can easily be built within a js-function.
________________________
Fredrik Klarqvist
-
May 17th, 2001, 04:29 AM
#3
Thread Starter
Frenzied Member
Not Quite ...
I'm using VB script, so is it possible you could tell me what the equivalent of that HTML code is ?
I'm only trying to store the value in a temporary variable. It will be used to update a database field later on.
-
May 17th, 2001, 04:42 AM
#4
Lively Member
Hello, the code translated to VBScript is almost the same:
Code:
<html>
<body>
<script language=VBSCRIPT>
sub getText(objItm)
dim strVal
strVal = objItm(objItm.selectedIndex).text
msgbox "The value is: " &strVal
end sub
</script>
<form name="frm">
<select name="sel">
<option value="1">VB</option>
<option value="2">ASP</option>
</select>
<br>
<input type="button" onClick="getText(document.frm.sel)" value="click me">
</form>
</body>
</html>
That should do it!
________________________
Fredrik Klarqvist
-
May 17th, 2001, 05:14 AM
#5
Thread Starter
Frenzied Member
hanks for all your help Fredrick, but I don't think I am explaining myself very well.
I am using VB6, not HTML script, for this project. My HTML page is designed using the VB6 DHTML Page Designer (which is pretty rubbish I know !). I have physical VB code attached to my ActiveX objects.
Therefore I am trying something alonng the lines of :
*****************************************
Private Sub cboNeworMod_onchange()
NeworMod = cboNeworMod.Value
End Sub
*****************************************
The problem with this is that .VALUE returns an empty string, which is less than ideal.
The user has 2 possible choices:- "New" or "Modification".
If they click on screen and change it then I want to store "New" or "Modification", depending on which one they clicked.
Later on this text will update a field on a database record that will be created.
I hope that makes more sense, and thanks very much for the help so far. I appreciate I could make my life a lot easier if I brushed up on HTML, but at the moment I don't have the time !
-
May 17th, 2001, 05:36 AM
#6
Lively Member
ok, I give it try again...
Code:
Private Sub sel_onchange()
strVal = sel.Item(sel.selectedIndex).Text
MsgBox strVal
End Sub
I've tried this myself from VB and it works fine. (sel is the name of the select-box).
I hope this will do it!
________________________
Fredrik Klarqvist
-
May 17th, 2001, 05:40 AM
#7
Thread Starter
Frenzied Member
Thank You.
Thanks Fredrick.
That is exactly what I needed and it now works perfectly.
Thanks a lot for all your help.
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
|