PDA

View Full Version : Parsing a number in an input field.


BjV
12-05-2002, 04:31 PM
Hello All,

I need to know how to parse a number like 02pm002314 when typed into an input field so that each part of the number is input into a url.

EX: website.com/PDFfiles/02p/02pm01/02pm012314.pdf

Up until now I been using,
("http://www.website.com/PDFfiles/" + document.myForm.CaseNum.value + ".pdf")
but this only allows me to access one folder.

Thanks BJV

Adam20002
12-05-2002, 04:58 PM
Hi,

Im not sure if i have got this right but do you want the number split into certain sections which will in turn create the path to the relevant PDF file ?

BjV
12-05-2002, 05:18 PM
That is correct.
The first three digits 02p corresponds to the folder for the correct year.
The first six digits 02pm01 corresponds to the folder for the correct case ID.
The entire number 02pm002314 corresponds to the correct PDF file.

Follow my path?

ShriekForth
12-05-2002, 05:33 PM
Like this?

<script type="text/javascript">
function parseCase(){
working = new String(document.myForm.CaseNum.value);
if (working.length == 10){
dir = working.slice(0 , 3);
subDir = working.slice(0 , 6);
file = document.myForm.CaseNum.value + ".pdf";
document.myForm.location.value = "/" + dir + "/" + subDir + "/" + file;
}
else{
alert("Invalid case number");
}
}
</script>
<form name="myForm">
<input type="text" name="CaseNum" value="02pm012314">
<br>
<input type="text" name="location" value="" size="50">
<br>
<a href="javascript:parseCase()">Get folder</a>


ShriekForth

BjV
12-05-2002, 06:35 PM
ShriekForth,

Thank you for the code.

I tried your code at the following URL:
http://topgun-web.com/Search2.html
but it doesnt seem to work properly did I insert the url wrong?
Also I don't really want the URL displayed if that is what the second Input field is for. I just want to type in the case number and get the file.

Would you please look at the source code,
Sorry if Im being a pain.

ShriekForth
12-05-2002, 07:40 PM
Yes, the second form field was there jus to show the new url. I was not sure what you intended to do with it. You need one change to make it go to that document.

replace

document.myForm.location.value = "http://www.topgun-web.com/Test/" + dir + "/" + subDir + "/" + file;

with

window.location="http://www.topgun-web.com/Test/" + dir + "/" + subDir + "/" + file;

ShriekForth

BjV
12-05-2002, 10:11 PM
Thank you ShriekForth,

I know it's close,
The code even makes some sense to me. I'm sure I have my path setup right.
Test/02p/02pm01/02pm012314.pdf
But I can't see what I'm doing wrong. Maybe I've been staring at it too long.

ShriekForth
12-06-2002, 01:37 PM
Did the file get moved? Yesterday when I tried it, I did get a pdf file.

ShriekForth

BjV
12-06-2002, 03:07 PM
I got it to work this morning by replacing,


<a href="javascript:parseCase()">Get folder</a>
with
<input type="button" value="Get Case" onClick="parseCase();">

Thank you so much, once again:thumbsup:

BjV