Results 1 to 8 of 8

Thread: JScript, ASP: Validation

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    JScript, ASP: Validation

    I looked for this everywhere and I cannot find my answer, everyone uses VBScript.

    What I have is a query that passes in a few values.

    myPage?num=1&text=hi

    in my ASP statement I do

    Code:
    num = Request('num');
    text = Request('text');
    If I pass in myPage?num=1 it will return an undefined value for text. I know if I tried
    Code:
    if(text == 'undefined')
     //work here
    it will not work. Neither will using null or ''. Can I somehow validate my vars and prevent this?

    I tried using try and catch but these did not work.

    Thanks for any help. I'm at the end of the road for this one.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    I'm not really following you. What are you trying to achive?
    Check passed values with client side Java Script? I'm really confused.

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Sorry for confusion.

    What i mean is this:

    myPage.asp
    Code:
    var intOrder = Request('order');
    var intNum = Request('num');
    In order for the request to work, myPage would have to be accessed like so:

    myPage.asp?order=1&num=2

    correct? But if the user took out order

    myPage.asp?num=2

    when I try to do work with intOrder, it will be null, or undefined. I need to be able to see if this is the case.

    I tried using

    if(intOrder == "null)
    if(intOrder =="undefined)
    if(intOrder == '')
    then change intOrder to a valid var.

    ect ect. and none of my solutions work.

    Hope that helps
    -----

    So in summary, all i want to know how to do is make sure my Requested variables are valid.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    OK,
    in ASP I use this:
    Code:
    intOrder=request("order")
    
    if intOrder="" then intOrder=0
    
    OR
    
    if Len(intOrder)=0 then intOrder=0
    In ASP all variables are Variant type. You could convert its value by using CDbl, CInt, Int, CCur, etc.

    Another thing: If you try to operate intOrder in JavaScript function, you need to pass your arguments as so:
    Code:
    <script language="JavaScript">
    function showValue(intOrder){
        alert(intOrder);
    }
    </script>
    
    <%
    Dim intOrder
    
    intOrder=request("order")
    if len(intOrder)=0 then intOrder=0
    
    %>
    
    <input type="button" name="ShowValue" value="Show Value" onclick="showValue(<%=intOrder%>)">
    I hope I made myself clear.

  5. #5

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    I understand what you mean but that dosent work. Here is my code:

    Code:
    <%@ Language="Javascript" %>
    
    <%
    	var intOrd = parseInt(Request('ord')); //Asc or Desc
    
    	
    	
    	if (intOrd == '0)  //Also tried == '' and == ""
    		Response.Write("Blank field");
    %>
    I know that len does not exist when coding ASP in JScript, it only works with VBScript. I'm wondering if there is a substring function or something.

    Anyhow, I have no clue. Any other ideas?
    Thanks for all the help anyways.


    BTW: If I write out intOrd it has a value of 1.#QNAN
    ***?

    I think I may have to resort to:

    if( (intOrd > 0) && (intOrd < 5) )

    or something like that.
    Last edited by invitro; Jul 30th, 2003 at 01:00 AM.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  6. #6
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    why not just validate using VBSCRIPT, its easier

  7. #7

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Well my whole entire site is made in JScript so switching to VB script wouldent be possible. (It calls external JS files ect. ect)

    So i really have to use javascript, perhaps in the future I will think about VBScript.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  8. #8

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Well if anyone else is interested, I solved the problem for Integers ONLY.

    after you do

    whatever = parseInt(Response('var'));

    you can then just simply do

    if(!whatever)
    whatever = right value.


    I'm still working on strings.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

Posting Permissions

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



Click Here to Expand Forum to Full Width