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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anyone convert this VBscript to JavaScript?

Status
Not open for further replies.

TGood

Programmer
Jun 6, 2003
10
US
<%
for each item in Request.Form
if left(item, 1) = &quot;C&quot; then '*** This is a checkbox
Response.write &quot;document.Form1.&quot; & item & &quot;.checked = true;&quot; & vbCrlf
end if
if left(item, 1) = &quot;T&quot; then '*** This is a textbox
Response.write &quot;document.Form1.&quot; & item & &quot;.value ='&quot; & Request.form(item)& &quot;';&quot; & vbCrlf

end if
next 'item
%>

 
that can't be converted to client scripting. we need to know what you want to do. we can make it similar but what exactely do you want the script to do. the fact you are utlizing a condtiion with a request object leaves doubt on a valid conversion.
at this point I can come up with a suedocoded function like this but it doesn't amke sense.
for(x = 0; x <= document.forms[0].length; x++) {
if(document.forms[0].element[x].name.substr(0,1)==&quot;C&quot;) {
document.write document.forms[0].element[x].name + &quot;=true&quot;;
} else {
if(document.forms[0].element[x].value.substr(0,1)==&quot;T&quot;) {
document.write document.forms[0].submit();
//or add the value to a hidden form field
//I don't understand what you are doing here though
}
}

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
I designed this VBscript to access checkboxes values begining with &quot;C&quot; and the assigned box number (ex. C1, C2, C3...). This script is repeated with the textboxes (ex. T1, T2, T3...). The checkboxes and Textboxes are all located on one form when the client checks a box or enters a text that information is tranferred to a printable form with there information he/she has entered. I hope this information makes my request clearer.
 
so you want this to be server side jscript then?
or are you combining everything onto one page now

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
Yes, with this VBscript I was able to capture all the checkboxes that were checked and all of the Textboxes that were entered. I was told to change the script to JavaScript.
 
well, here's a stab at it. I've used jscript numerous times but never to go through the form collection. may have some syntax issues but that should be fixed with some searches on the specific syntax for jscript and asp.
<%@ LANGUAGE=JScript %>
var val = &quot;&quot;;

for(x = 0; x < Request.Form.length; x++) {
val = Request.Form
if((val.name.substr(0,1)==&quot;C&quot;)&&(val.checked==&quot;on&quot;)) {
Response.Write &quot;document.Form1.&quot; & val.name & &quot;.checked = true;&quot; & &quot;<br>&quot;
} else {
if((val.name.substr(0,1)==&quot;T&quot;)&&(val.value.length>0)) {
Response.write &quot;document.Form1.&quot; & val.name & &quot;.value ='&quot; & Request.form(x)& &quot;';&quot; & &quot;<br>&quot;
}
}
}
}
%>

if this does not go quite well then I would suggest reading up on the Form Collection with jscript

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
Your awesome! Thanks for everything.
 
I guess instead of jsut posting some code I'll explain what I did to get this far. maybe it
will help you with future requests of the same type.
the question at hand was to convert vbscript to jscript server side.

first step was to search for syntax on the form collection in jscript.
functions known to need were .length, for loop in jscript, and if syntax.
after that you can build the function

second I wroite a client level script to perform the task to check for accuracy in javascript
here is that. (IE only)
<html>
<head>
<script language=&quot;javascript&quot;>
function runIt() {
var val = &quot;&quot;;
var nam = &quot;&quot;;
for(x = 0; x < iniFrm.length; x++) {
val = document.iniFrm.elements[x]
if((val.name.substr(0,1)==&quot;C&quot;)&&(val.checked==true)) {
newBok.innerHTML=newBok.innerHTML+&quot;<input type='checkbox' name=&quot;+val.name+&quot; CHECKED><br>&quot;;
} else {
if((val.name.substr(0,1)==&quot;T&quot;)&&(val.value.length>0)) {
newBok.innerHTML=newBok.innerHTML+&quot;<input type='text' name=&quot;+val.name+&quot; value=&quot;+val.value+&quot;><br>&quot;;
}
}
}
}
</script>
</head>
<body>

<form name=&quot;iniFrm&quot;>
<input type=&quot;checkbox&quot; name=&quot;CHECK1&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;NOCHECK2&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;CHECK3&quot;><br>
<input type=&quot;text&quot; name=&quot;TEXTBOX1&quot;><br>
<input type=&quot;text&quot; name=&quot;NOTEXTBOX2&quot;><br>
<input type=&quot;text&quot; name=&quot;TEXTBOX3&quot;><br>
<input type=&quot;button&quot; value=&quot;run it&quot; onClick=&quot;runIt()&quot;>
</form>

<form id&quot;newBok&quot; name=&quot;newBok&quot;>
</form>
</body>
</html>

Then I just converted that function verses converting the vbscript to jscript
This is the process I like to always take when I need to perfomr things as this.
again
1) get syntax and functions needed in langauge
2) search for similar examples for logic flow
3) write a client level exmaple for ease of testing
4) convert client to server with found needed changes in search
5) test and search for needed fix to errors
6) final tests

thus I came up with the above code. again not tested and unsure but it looks valid
or at least closer then before [wink]

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
thanks, but I'm only awesome if it works [lol]

glad this got you closer and helped out

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top