...

View Full Version : useing javascript in asp



Crash1hd
06-10-2003, 09:42 AM
This is a great little javascript I found that converts ascii to binary and vise versa what I was wondering is how I could change it so that when you submit info on a page it does the conversion and submits the binary value? instead so that the new page that loads shows the binary value or vise versa

here is the script that I found



<html><head><title>Convert Binary to ASCII or ASCII to Binary</title>

function dobin(text,sepa) {
var letbin = ""
for (i=0; i<text.length;i++) {

let = text.substr(i,1);

if (i>0) {
var sep = sepa;
if (i % 10 == 0) {
letbin=letbin+'<BR>'
}
}
else {
var sep = "";
}

//Ascii -- Binary Code

//Numbers:
if (let == "0") {letbin = letbin + sep + '00110000'}
if (let == "1") {letbin = letbin + sep + '00110001'}
if (let == "2") {letbin = letbin + sep + '00110010'}
if (let == "3") {letbin = letbin + sep + '00110011'}
if (let == "4") {letbin = letbin + sep + '00110100'}
if (let == "5") {letbin = letbin + sep + '00110101'}
if (let == "6") {letbin = letbin + sep + '00110110'}
if (let == "7") {letbin = letbin + sep + '00110111'}
if (let == "8") {letbin = letbin + sep + '00111000'}
if (let == "9") {letbin = letbin + sep + '00111001'}

}
binary.innerHTML = letbin
return false;
}

function doasc(text) {

//if (text.length % 8 != 0) {
// alert (text + " is not an even binary.\n\nYou may have missed a digit or maybe added an additional digit/character.\n\nSeparators are NOT required here.")
// return false;
// last;
//}

var letasc = ""
lettot = text.length / 8
j=0
for (i=0; i<lettot;i++) {

let = text.substr(j,8);

//Numbers:
if (let == "00110000") {letasc = letasc + '0'}
if (let == "00110001") {letasc = letasc + '1'}
if (let == "00110010") {letasc = letasc + '2'}
if (let == "00110011") {letasc = letasc + '3'}
if (let == "00110100") {letasc = letasc + '4'}
if (let == "00110101") {letasc = letasc + '5'}
if (let == "00110110") {letasc = letasc + '6'}
if (let == "00110111") {letasc = letasc + '7'}
if (let == "00111000") {letasc = letasc + '8'}
if (let == "00111001") {letasc = letasc + '9'}
if (letasc == "") {
alert ("not found")
break;
}
j=j+8
}
ascii.innerHTML = letasc
asciia.innerHTML = text.length
return false;
}
</head>

<body>

<form name="asc2bin">
<strong>Convert to Binary</strong>
<br />
Binary Code gets wordwrapped if longer then 10 digits! so use notepad if trying to conver back to remove space
<br />
Enter Text: <input type="Text" name="text" size="92">
<br />
Separate with: <input type="Text" name="separater" maxlength="1" size="1"> (optional)<br>
<input type="Submit" value="Convert" onclick="dobin(document.asc2bin.text.value,document.asc2bin.separater.value);return false"><br>
</form>

<div name="binary" id="binary">Binary Conversion will show here.</div>

<br>

<form name="bin2asc">
<strong>Convert to Ascii</strong>
<br />
Enter Binary: <input type="Text" name="text" size="90">
<br />
<input type="Submit" value="Convert" onclick="doasc(document.bin2asc.text.value);return false"><br>
</form>

<div name="ascii" id="ascii">ASCII Conversion will show here.</div>
<div name="asciia" id="asciia">ASCII Length will show here.</div>

</body>
</html>


This is the code I would use instead of course doesnt work?


<html><head><title>Convert Binary to ASCII or ASCII to Binary</title>
</head>

<%
'************************************ MAIN PROGRAM

Select Case CInt(Request.QueryString("dbshow"))
Case 1
Thanks()
Case Else
Input()
End Select

'******************************** End MAIN PROGRAM
%>

<%Sub Input() '''''''''''''''''''''''''''''''''''%>
<body>
<script language="JavaScript" src="/Scripts/Ascii2Bin.js"></script>
<form name="asc2bin" action="testpage.asp?dbshow=1" method="post">
<strong>Convert to Binary</strong>
<br />
Binary Code gets wordwrapped if longer then 10 digits! so use notepad if trying to conver back to remove space
<br />
Enter Text: <input type="Text" name="text" size="92">
<br />
Separate with: <input type="Text" name="separater" maxlength="1" size="1"> (optional)<br>
<input type="Submit" value="Convert" onclick="dobin(document.asc2bin.text.value)"><br>
</form>

<br>

<form name="bin2asc">
<strong>Convert to Ascii</strong>
<br />
Enter Binary: <input type="Text" name="text" size="90">
<br />
<input type="Submit" value="Convert" onclick="doasc(document.bin2asc.text.value);return false"><br>
</form>

<div name="ascii" id="ascii">ASCII Conversion will show here.</div>
<div name="asciia" id="asciia">ASCII Length will show here.</div>
<%End Sub '''''''''''''''''''''''''''''''''''''''''''%>

<%Sub Thanks() '''''''''''''''''''''''''''''''''''%>
<% bin = Request.Form("text")%>
<input type="Text" name="texta" size="92" value="<%=bin%>">
<%
Response.Write "<SCRIPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write "dobin(document.asc2bin.texta.value);" & vbCrlf
Response.Write "</SCRIPT>"
%>
<body>
<%

response.write(bin)

End Sub '''''''''''''''''''''''''''''''''''''''''''%>
</body>
</html>


useing the js to hold all of the script info

Spudhead
06-10-2003, 10:16 AM
Could you not just put some hidden fields in the form to carry the converted values, and make the functions submit the form (ie: validation) instead of changing the innerHTML?

Crash1hd
06-10-2003, 10:57 AM
I am not sure how to change the innerHTML part?? in code that is?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum