Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onclick value of field check

    The Following code for somereason doesnt work in netscape 4.7 works great in all other browsers?

    Code:
    function trimtext(txt){
    var temptext=txt.replace(/\s*/,'');
    ets = temptext.substring(temptext.length-1, temptext.length);
    while(ets==" "){
    temptext = temptext.substring(0, temptext.length-1);
    ets = temptext.substring(temptext.length-1, temptext.length);
    }
    return temptext;
    }
    
    	function CheckObits(x)
    	{
    		var tempstr = trimtext(x.value);
    		var temparray = tempstr.split(/\s+/);
    		var arylen = temparray.length;
    
    		var over50 = arylen-50;
    		var over100 = arylen-100;
    		var over250 = arylen-250;
    		var over350 = arylen-350;
    		var Obit = document.Form1;
    		var D = new Date();
    		var Year = D.getFullYear();
    
    		if (Obit.PurchaseField.value == "50")
    		{
    			if (arylen >= "51")
    			{
    				if (arylen <= "100")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 100 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "101")
    			{
    				if (arylen <= "250")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 250 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "251")
    			{
    				if (arylen <= "350")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 350 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "351")
    			{
    				alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose Unlimited word Obituary!");
    				return
    			}
    		}
    		Obit.submit()
    	}
    I know that its check the field but the alerts are not being displayed (the reason I know that it is checking is because If i remove Obit.submit() then when I click on submit it wont change the page

    here is what is in the htm page

    Code:
    			<input type="Button" value="Submit" onclick="CheckObits(DetailsField);">&nbsp;

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think for NS4 version browsers you need to chang your function call to this:
    <input type="Button" value="Submit" onclick="CheckObits(document.form1.DetailsField.value);">

    Then change this line in your function:
    var tempstr = trimtext(x);

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I did the changes that you had indicated but it still does the same thing as before which is if I have text in the box more then 50 words it still lets it through

    Ok I noticed that when I run the code above it works fine in netscape but the problem is when I have more then one I relized that after

    so the problem is with this code

    Code:
    		if (Obit.PurchaseField.value = "50")
    		{
    			if (arylen >= "51")
    			{
    				if (arylen <= "100")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 100 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "101")
    			{
    				if (arylen <= "250")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 250 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "251")
    			{
    				if (arylen <= "350")
    				{
    					alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose 350 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "351")
    			{
    				alert("You are " + over50 + " Word\(s\) Over!\nPlease shorten Obituary or choose Unlimited word Obituary!");
    				return
    			}
    		}
    		if (Obit.PurchaseField.value = "100")
    		{
    			if (arylen <= "50")
    			{
    				alert("You are useing less then 50 Words!\nPlease add to Obituary or choose 50 word Obituary! Which is free \:\)");
    				return
    			}
    			if (arylen >= "101")
    			{
    				if (temparray.length <= "250")
    				{
    					alert("You are " + over100 + " Word\(s\) Over!\nPlease shorten Obituary or choose 250 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "251")
    			{
    				if (temparray.length <= "350")
    				{
    					alert("You are " + over100 + " Word\(s\) Over!\nPlease shorten Obituary or choose 350 word Obituary!");
    					return
    				}
    			}
    			if (arylen >= "351")
    			{
    				alert("You are " + over100 + " Word\(s\) Over!\nPlease shorten Obituary or choose Unlimited word Obituary!");
    				return
    			}
    		}
    		Obit.submit()
    	}
    Also tried else if doesnt work

    so what I want to do is I have a drop down that has choices of 50 100 250 ext... and a comment box that the value has to be less then or equal to the number in the drop down
    Last edited by Crash1hd; 06-13-2003 at 09:36 PM.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    are these just typos in your post?

    if (Obit.PurchaseField.value = "50")

    ...

    if (Obit.PurchaseField.value = "100")


    you should use == instead.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When I use == which I had originally then netscape doesnt do what I want it to do at all but if I use just = and have just the one choice it works!

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    if you do it that way, you are not checking for a condition but just assigning that field the value, and all the succeeding statements will be executed.

    if (Obit.PurchaseField.value = "50")//assigns purchase field to 50
    {
    //statements here will be executed
    }

    if (Obit.PurchaseField.value = "100")//assigns purchase field to 100
    {
    //statements here will ALSO be executed
    }


    Is that the way it is supposed to work?

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no its just supposed to check the value then if the condition is false then excute the alerts

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    That's exactly what I was pointing out to you. Use == not =.

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok cool but when I use == netscape doesnt do what I want it to do?

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    post the whole code and I can test it for you. I have NS4.78 in my machine.

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the 2 files that are used! Hope that works
    Attached Files Attached Files

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    I haven't run the page because it is an asp page.

    But I noticed, as requestcode pointed out earlier, you should change the function call to:

    <input type="Button" value="Submit" onclick="CheckObits(this.form.DetailsField);">

    or

    <input type="Button" value="Submit" onclick="CheckObits(document.forms[0].DetailsField);">


    to reference a field PROPERLY, you should follow this syntax:

    document.formNameHere.elementNameHere

    IE allows referencing fields by just the name but this is not the proper way. You should make it a habit to do it the correct way.

    Try also naming your form.

  • #13
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yep tried that unfortunatly that didnt fix the problem and for some reason I have to name the form as Form1 due to another Javascript where I tried to change it but the javascript faled to run so I was not really woried about it!

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    remove the quotes in all the arylen conditions like:

    if (arylen >= 51)

    and try alerting at the start of the function

    function CheckObits(x)
    {
    alert(x);//should alert object
    ...

    you can easily debug if you can find the error message displayed by NS4. type javascript&#58; in the address bar to open the Javascript console.

  • #15
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok but it doesnt cause an error it just ignores it like there was nothing to check?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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