Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting JavaScript to VBScript for a newbie.

Status
Not open for further replies.

sigrney

Programmer
Aug 13, 2001
7
US
Hi all, I am pretty new to VBscript. Can anyone help me convert the following JavaScript to VBScript:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function checkRequired_onsubmit() {
var returnValue = false;
var newValue;
if (document.theForm.textbox.value == &quot;&quot;) {
newValue = prompt(&quot;Reqired field 'My Text Box'. Please enter a value:&quot;, &quot;&quot;);
document.theForm.textbox.value = newValue;
}
else {returnValue = true;}
return returnValue;
}
</SCRIPT>

And the associated form looks like this:

<FORM NAME=&quot;theForm&quot; METHOD=&quot;POST&quot;
ACTION=&quot;/examples/servlet/MyServlet&quot; onsubmit=&quot;return checkRequired_onsubmit()&quot;>


With a submit like this:

<INPUT TYPE=&quot;submit&quot; VALUE = &quot;Update&quot;>

I also need to call another VBScript sub before returning to do the submit, let's say it name is 'sub doSomething'

TIA!! :)
 
A straightforward translation looks like what follows.

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Function checkRequired_onsubmit()
Dim returnValue, newValue
returnValue = false
If (document.theForm.textbox.value = &quot;&quot;) Then
newValue = InputBox(&quot;Reqired field 'My Text Box'. Please enter a value:&quot;,,&quot;&quot;)
document.theForm.textbox.value = newValue
Else
returnValue = true
End If
checkRequired_onsubmit = returnValue
End Function
</SCRIPT>

See if it works for you.

regards - tsuji
 
Hmmm, well that works fine for one field, but what if I need to check multiple fields before allowing the submit? I tried using End if and Else if in different places. I am getting scripting errors. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top