Click to See Complete Forum and Search --> : VBscript vs JAVAscript
Im currently working on a project and the previous designer was weak and left me with a lot of sh1t to clear up. One of the major tasks is converting some of the pages code from vbscript to javascript..... does anyone know of a good converter???
Tweak4
07-10-2007, 10:37 AM
Not only do I not know of a good converter, I don't know of any converter... Being that the languages are pretty fundamentally different, there is a good chance that no converter exists, and if one does, there is an even better chance that it doesn't work all that well.
More than likely, if you want it converted, you're going to have to go in and do it by hand.
you can convert as there is a converter Here (http://slingfive.com/pages/code/scriptConverter/demo.html).
Asides from that I have sort of converted it...... :mad:
here is the original VBScript..........
Sub ValidatePage()
dim minDays, maxMonths, maxDaysBooked
minDays = 3
maxMonthsAhead = 12
maxDaysBooked = 60
If Not IsDate(SearchSpace.DateStart.Value) then
alert("Start date is not a valid date")
ElseIf Not IsDate(SearchSpace.DateFinish.Value) then
alert("End date is not a valid date (is it blank?)")
ElseIf Cdate(SearchSpace.DateStart.Value) > Cdate(SearchSpace.DateFinish.Value) then
alert("Start date is greater than end date")
'check that start date IS NOT later than maxMonths ahead in time
ElseIf Cdate(SearchSpace.DateStart.Value) < Date() then
alert("Start date can not be in the past")
'check that start date IS NOT equal to end date
ElseIf Cdate(SearchSpace.DateStart.Value = SearchSpace.DateFinish.Value) then
alert("Start date can not be equal to End Date")
'check that start date IS NOT later than maxMonths ahead in time
ElseIf Cdate(SearchSpace.DateStart.Value) > dateadd("m", maxMonthsAhead, Date()) then
alert("Start date can not be later than " & CStr(maxMonthsAhead) & " months ahead")
'check that difference IS NOT greater than maxMonths ahead in time
ElseIf DateDiff("d", SearchSpace.DateStart.Value, SearchSpace.DateFinish.Value, vbSunday) > maxDaysBooked then
alert("Maximum no. of days booked should not exceed " & CStr(maxDaysBooked) & " . Contact us for details.")
'check for minimum days
ElseIf Cdate(SearchSpace.DateFinish.Value) < dateadd("d", minDays, SearchSpace.DateStart.Value) then
alert("Minimum stay is " & CStr(minDays) & " days, you'll be charged for " & CStr(minDays) & " days if you carry on.")
SearchSpace.submit()
Else
SearchSpace.DeptTime.Value = SearchSpace.DeptTimeHour.value & ":" & SearchSpace.DeptTimeMinute.value
SearchSpace.ArrTime.Value = SearchSpace.ArrTimeHour.value & ":" & SearchSpace.ArrTimeMinute.value
SearchSpace.submit()
End If
End Sub
and this is what i converted it to..........
function ValidatePage(){
var minDays, maxMonths, maxDaysBooked;
minDays = 3;
maxMonthsAhead = 12;
maxDaysBooked = 60;
if(! IsDate(SearchSpace.DateStart.Value)){
alert("Start date is ! a valid date");
}else if(! IsDate(SearchSpace.DateFinish.Value)){
alert("End date is ! a valid date (is it blank?)");
}else if(Cdate(SearchSpace.DateStart.Value) > Cdate(SearchSpace.DateFinish.Value)){
alert("Start date is greater than end date");
//check that start date IS ! later than maxMonths ahead in time;
}else if(Cdate(SearchSpace.DateStart.Value) < Date()){
alert("Start date can ! be in the past") ;
//check that start date IS ! equal to end date ;
}else if(Cdate(SearchSpace.DateStart.Value == SearchSpace.DateFinish.Value)){
alert("Start date can ! be equal to End Date") ;
//check that start date IS ! later than maxMonths ahead in time;
}else if(Cdate(SearchSpace.DateStart.Value) > dateadd("m", maxMonthsAhead, Date())){
alert("Start date can ! be later than " + CStr(maxMonthsAhead) + " months ahead");
//check that difference IS ! greater than maxMonths ahead in time;
}else if(DateDiff("d", SearchSpace.DateStart.Value, SearchSpace.DateFinish.Value, vbSunday) > maxDaysBooked){
alert("Maximum no. of days booked should ! exceed " + CStr(maxDaysBooked) + " . Contact us for details.");
//check for minimum days ;
}else if(Cdate(SearchSpace.DateFinish.Value) < dateadd("d", minDays, SearchSpace.DateStart.Value)){
alert("Minimum stay is " + CStr(minDays) + " days, you'll be charged for " + CStr(minDays) + " days if(you carry on.");
SearchSpace.submit;
}else{
SearchSpace.DeptTime.Value = SearchSpace.DeptTimeHour.value + ":" + SearchSpace.DeptTimeMinute.value;
SearchSpace.ArrTime.Value = SearchSpace.ArrTimeHour.value + ":" + SearchSpace.ArrTimeMinute.value;
SearchSpace.submit;
} ;
}
but it doesnt want to work...........
can anyone help?
Tweak4
07-11-2007, 11:25 AM
Have you actually taken the time to look at this and attempt to debug it, or did you just post what came out of that converter?
Problems I see:
1. IsDate() isn't a built in function in Javascript. Unless you have this function defined elsewhere, every call to this is going to cause an error.
2. Cdate() - see #1
3. SearchSpace references - the references you have might work, but not reliably. You'd be farther ahead changing them to use document.getElementById to retrieve your form values instead.
Side note #1- Unless your users are programmers, they'll have no idea what "Start date is ! a valid date" means.
Side note #2- this is not a difficult or overly-complex validation, so why bother trying to "convert" it from a VBScript version at all? Given all of the rules and the rest of the code for this page, I honestly think I could have written the validation from scratch in less time than it took me to compose this response.
problem is im not to hot on javascript... I can edit and manipulate but i havent ever written my own javascript before...