Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


DOM and VBScript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36075
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> DOM and VBScript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 DOM and VBScript - 7/10/2006 2:49:30 AM   
  ullevi83

 

Posts: 5
Score: 0
Joined: 7/10/2006
Status: offline
Dear All,

my first post on here, wondering if anyone has a solution to a problem I am having.

I have a dynamic asp page created through an access db, which all works fine.  I output several text boxes which are dynamically named depending on the db fields.

The problem I am having is, I am using the onChange event to calculate a value within the text boxes and Im not sure if it is possible to do this, but can you extract a value from a text box and use it in a sub if you do not know the name value of the text field??

Example Code is something along the line of this:-

<form name="quoteDetails">
    <input type=text name=<%dbField1%> value="0" onChange=calculate()>
    <input type=text name=<%dbField14%> value="0" onChange=calculate()> 
</form>

<script language=vbscript>
  sub calcualte()
     dim sCode
    sCode = document.QuoteDetails.elements.value  'This is the problem, how do I extract the value from the text box if I do not know the name of the field???
  end sub
</script>

I can get the value to return if I was to individually name each text box, but as they are dynamically named due to user manipulation, it would be a real mindfield.

Thanks for your help.

_____________________________

"A man's got to know his limitations"
 
 
Post #: 1
 
 RE: DOM and VBScript - 7/10/2006 2:58:08 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi ullevi83,

is calculate() a client or a server side sub?

(in reply to ullevi83)
 
 
Post #: 2
 
 RE: DOM and VBScript - 7/10/2006 3:27:02 AM   
  ullevi83

 

Posts: 5
Score: 0
Joined: 7/10/2006
Status: offline
Hi ehvbs
 
It is a client side sub.  Sorry should have been clearer.
 
Thanks

_____________________________

"A man's got to know his limitations"

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: DOM and VBScript - 7/10/2006 3:28:58 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
To save some time if we are talking about client side scripting:

This code:


      

shows how to use parameters to get information to a sub.

For those people interested in (parentheses) and/or seeing a programmer eating his old code:

Yes, I changed my old/bad/naive code

        <input type = "BUTTON" id = "id_Btt01" value = "01" onclick = 'oneForAll( Me )'>

to the new/better version above.

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: DOM and VBScript - 7/10/2006 4:12:08 AM   
  ullevi83

 

Posts: 5
Score: 0
Joined: 7/10/2006
Status: offline
ehvbs,
 
Do you have an example of using onChange event from a textbox?

Thanks


_____________________________

"A man's got to know his limitations"

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: DOM and VBScript - 7/10/2006 4:22:08 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Sure,


      

(in reply to ullevi83)
 
 
Post #: 6
 
 RE: DOM and VBScript - 7/10/2006 10:05:04 PM   
  ullevi83

 

Posts: 5
Score: 0
Joined: 7/10/2006
Status: offline
Thanks ehvbs

that is a good example.

Have you ever written anything like this?

basically you have a simple form say:

<form name="form1">
 <input type=text name="field1" value="0" onChange="Calculate()">
 <p>Total Pay After Tax Is - <script language=vbscript>document.write(call calculate())</script></p>
</form>

your script does the following simple calculation:

<script language="vbscript">
function calculate()
   dim itxtfield, iTotal, iTax
   itxtfield = document.form1.field1.value
   iTax = CInt(17.5)
   iTotal = itxtfield - ((itxtfield / 100) * iTax)
end function
</script>

how would you return the value iTotal from the script to the form above??

_____________________________

"A man's got to know his limitations"

(in reply to ehvbs)
 
 
Post #: 7
 
 RE: DOM and VBScript - 7/10/2006 10:33:35 PM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi ullevi83,

no, I haven't. If I were asked to write a script doing what your question implies,
I would use this proof of concept code


      

to help me think about an answer.

(in reply to ullevi83)
 
 
Post #: 8
 
 RE: DOM and VBScript - 7/11/2006 1:29:46 AM   
  ullevi83

 

Posts: 5
Score: 0
Joined: 7/10/2006
Status: offline
Thanks Ehvbs for your help,

I came up with this, seems to do the trick, but is obviously just whacked together, it gives me the desired effect.

<script language="vbscript">
function calculate()
 dim itxtfield, iTotal, iTax
 calculate = 0
 itxtfield = document.form1.field1.value
 iTax = CInt(17.5)
 iTotal = itxtfield - ((itxtfield / 100) * iTax)
 Calculate = document.write(iTotal)
end function
</script>
</head>
<body>
<form name="form1">
 <input type=text name="field1" value="0" onChange="Calculate()">
</form>
</body>
</html>

_____________________________

"A man's got to know his limitations"

(in reply to ehvbs)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> DOM and VBScript Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts