Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    10

    Unanswered: covert java script to vb script

    Hello everyone I am having trouble converting this codes.I want to convert this codes to vbscript: to validate if the user enter text on each field.

    <script Language="JavaScript">
    function FrontPage_Form1_Validator(theForm)
    {
    if (theForm.company_name.value == "")
    {
    alert("Please enter a value for the \"Company_name\" field.");
    theForm.company_name.focus();
    return (false);
    }
    if (theForm.company_add.value == "")
    {
    alert("Please enter a value for the \"company_add\" field.");
    theForm.company_add.focus();
    return (false);
    }
    if (theForm.con_per.value == "")
    {
    alert("Please enter a value for the \"Con_per\" field.");
    theForm.con_per.focus();
    return (false);
    }
    if (theForm.con_no.value == "")
    {
    alert("Please enter a value for the \"con_no\" field.");
    theForm.con_no.focus();
    return (false);
    }
    return (true);
    }

    Any help much appreciated

    Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    With server-side validation you'll have to have a system to get back to the same or different page with messages.

    And here are some interesting server-side validation links:

    Server-Side Form Validation by Dianna Leech - 12/1/1999
    http://www.4guysfromrolla.com/webtech/120199-1.shtml

    An Email Validation Routine by Joo Vieira - 4/11/1999
    http://www.4guysfromrolla.com/webtech/041199-1.shtml
    Somewhat shorter.

    An Email Validation Script by Ben Durbin - 5/19/1999
    http://www.4guysfromrolla.com/webtech/051999-1.shtml
    Longer.
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  3. #3
    Join Date
    Jan 2006
    Posts
    10
    thanks... really helps...

  4. #4
    Join Date
    Nov 2005
    Location
    Honolulu HI
    Posts
    119
    he didnt say anything about server side validation.... and i would not suggest using it either. it adds extra processes, overhead, delay and bandwitdth usage...

    Iris
    while you may want to convert all of that to VB Script (which i love VB Script)
    vb Script only works in Internet Explorer. it does not work with Firefox and i dont think it wirks with netscape or opera browsers either.

    so only the peiople using IE would be able to use your site.

    i just spent 2 weekends and about 60 hours converting an entire website from VBScript to JavaScript all because the site would not work with any other browser.

    if you need help understanding how the Javascript works, i can help you. its almost identical to VBScript as far as logic is concerned.
    .
    .
    http://www.HawaiianHope.org
    Providing Technology services to non profit orgs, Homeless Shelters, Food Pantries, Clean And Sober Houses and more.
    To date we have given away over 900 free computers !
    __________________________
    caeli enarrant gloriam Dei !

  5. #5
    Join Date
    Jan 2006
    Posts
    10
    ... hello!!
    i want to covert it in vbscript inpite the fact that it only works in IE, i want still to covert it 'coz it is one of the requirement i need to meet but don't know how to code/do it in VBSCRIPT.
    can you help me??

  6. #6
    Join Date
    Nov 2005
    Location
    Honolulu HI
    Posts
    119
    here you go.
    includes some minor structural chages. i like it this way better.. it tells you all at once what is wrong with the form, instead of a pop up for each blank field seperately.
    then if there is no problems, it submits the form

    Code:
    <html>
    <body>
    <form name="CompanyData" action="testForm.htm" method="post">
    
    Company Name <input type="text" name="company_name"> <br>
    Company Address <input type="text" name="company_add"> <br>
    Contact Person <input type="text" name="con_per"> <br>
    Contact Number <input type="text" name="con_no"> <br>
    <br>
    <input type="button" value="Submit" onClick="FrontPage_Form1_Validator('CompanyData')">
    
    </form>
    </body>
    </html>
    
    <script Language="VBScript">
    
    sub FrontPage_Form1_Validator(theForm)
    
    	Set theForm = Document.forms(theForm)
    
    	strMessage=""
    
    	if theForm.company_name.value = "" then
    		strMessage ="Company Name" & vbCr
    		theForm.company_name.focus()
    	end if
    
    	if theForm.company_add.value = "" then 
    		strMessage = strMessage & "Company Address" & vbCr
    		theForm.company_add.focus()
    	end if
    
    	if theForm.con_per.value = "" then
    		strMessage = strMessage & "Contact Person" & vbCr
    		theForm.con_per.focus()
    	end if
    
    	if theForm.con_no.value = "" then 
    		strMessage = strMessage & "Contact Number" & vbCr
    		theForm.con_no.focus()
    	end if
    
    	' ---------------------------------------------------
    
    	if len(strMessage)>0 then
    		' if a strMessage exists then there was a problem, display it.
    		strMessage = "Please Enter Values for the Following Fields :" & vbCr & vbCr & strMessage 
    		alert strMessage 
    	else
    		' If the strMessage is empty, there was no problems, submit the form
    		theForm.submit()
    	end if
    
    end sub
    
    </script>
    .
    .
    http://www.HawaiianHope.org
    Providing Technology services to non profit orgs, Homeless Shelters, Food Pantries, Clean And Sober Houses and more.
    To date we have given away over 900 free computers !
    __________________________
    caeli enarrant gloriam Dei !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •