SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    lists and arrays

    Good morning:
    This seems simple enough so I'm sure some expert will be able to solve this quickly.
    I have a comma list of numbers such as (just an expamle):
    123,456,789,978

    I figured to put this into an array I could use the split command.
    What I need to do is test each number after the ',' to see if it begins with a 9. I figured if I put it into an array first it would be easy to test for the 9.
    Is that a good assumption and what is the easiest way to test for a 9 as the first digit after the comma or the first digit in each array cell?

    Thanks for the help

    Dan

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what up dfred,
    as far as whether it would be better to test for the 9 before or after the array, it depends on where you are going after that...
    searching for ",9*" delimited by another comma would be a pretty quick search with no need to place it into an array, however it also depends on the amount of numbers and the list or string, and then the return values could be put into the array, but i am not sure if the array is the final destination?
    please supply a little bit more info on the goal of this extraction and the most specific solution will be easier to make
    PEACE

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what up dfred,
    searching the set of numbers for a 9 may be easier before they are inserted into an array, but it depends on what is going to be done with the list of numbers after...
    it also depends on the amount of numbers,...
    searching through a string delimited by "," and looking for anything beginning with a 9 would be pretty quick and would not require the insertion into an array, unless the array itself was part of some other procedure...
    let me know what the context of the situation is here and maybe i can come up with the most appropriate solution
    PEACE

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok the ultimate goal is if a radio button is selected with a value of "bad", the string of numbers within a select box must have the ending number start with an '9'.
    ex:
    123,456,789,987

    if this is not true, then an alert will fire saying that the string does not have a '9' number string in it.
    There will also be another radio button and another text field associated to this also but first things first.
    I think I will be able to get the value for the radio button.
    I need to find the best way to then test for the '9**' string.
    lastly I need to display an alert message only if the radio value is 'bad' and the test string does not contain a '9**' string.
    Does that help explain what I am doing better?

    dan

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sup dan,
    the information helps quite a bit,
    You need:
    to evaluate if
    the string of numbers within a select box has the ending number start with an '9'.
    for example:
    34,232,653,938
                    ^
                    |
    ending number
    starts with 9, therefore fires the alert
    to check it,
    Code:
    <script language="javascript">
    	var startIndex, endIndex;
    	var answer = "";
    	var strNum = new String("34,983,23,944");
    
    	startIndex = strNum.lastIndexOf(",");
    	endIndex = strNum.length;
    
    	answer = strNum.substring(startIndex,endIndex);
    	if( answer.charAt(1) == "9")
    		alert( answer );
    	else
    		alert("the last number does not have a 9 as the first digit");
    
    </script>
    you could also increment the startIndex by 1 to move past the comma, and then answer.charAt(0) would be == to 9,
    i am not as familiar with reg expressions and i was trying to get a nasty little function ready for this bad larry, but i have to become a mobile vpn setup person for some guy in about an hour, and since we can't forget lunch, i have to supply you with this, which will work wonderful
    hope this helps
    keep them posts comin!
    PEACE

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks for that. I have a lot of work to do to get this to work, but it will do what I want. I will post anymore questions after I do some initial setup work.

    thanks

    dan

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good afternoon:
    Well I added the code in that was needed to get the JS to run and it did not totally do what I thought it was doing yesterday.

    the if ... =="9" is not ever correct. I added alert messages to see what answer was, and here is an example of what happened:

    string: 111, 123, 113

    answer: , 113

    startIndex: 12

    so from that info can you explain what the start index is and what answer is since the else part of the if satement always is firing.
    I think it is very close but i don't know what charAt(1) is so I don't know if it is starting in the wrong place or not.

    Thanks

    Dan

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out the problem with that. So the JS does what it is suppose to do. Now only two more parts to add to the JS before it is commplete.

    Thanks for you help this week. If I need you help on the next part, I'm sure you will be able to help.

    Have a good weekend

    Dan

  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good morning everyone; especially PCMOVER.

    The code that PCMOVER and I have been working on will be posted at the bottom. The code works for one text field related to the radio buttons value. Now what if I have multiple text fields related to that radio button. the code will show that the var strNum has a i value which is in a loop so the i value changes depending on the num value. for example there could be two text fields or more and the i value will change to 1 or 2 or ect depending on how many text fields there are.
    The following code works for one field but if there are multiple fields, then it the page cannot submit till all the fields are verified. I know I am close with the code I just need someone to look at what I have and help me along to find why the code will verify the first one, and if it is right, it submits without checking the second one and so forth. now if the first one is correct, then it will check the second one. here is the code. I hope I described what I need the code to do in an easy to follow way.
    Thanks for any help you can give.

    <script language="javascript">
    var num= <cfoutput>#form.weapon_count#</cfoutput>;
    function alt900_check(){
    var startIndex, endIndex;
    var answer = "";
    var msg = "Since you selected a Yield Code of Alt900, the string must have a 9** value.\nThe last number does not have a 9 as the first digit.\nIt is not a proper Alt900 String.";
    for (i=1;i<num+1;i++)
    {
    var strNum = eval("document.receipt.NumericAlts"+i+".value");
    startIndex1 = strNum.lastIndexOf(",");
    startIndex = startIndex1 + 1;
    endIndex = strNum.length;
    answer = strNum.substring(startIndex,endIndex);
    alert(strNum);alert(startIndex1);alert(startIndex);alert(endIndex);alert(answer);
    for (j = 0; j < 2; j++)
    {
    if (eval("document.forms[0].YIELDCODE" + "[" + j + "].checked"))
    {
    if( answer.charAt(1) == "9")
    {
    //return true;
    }
    else
    {
    alert(msg);
    // return false;
    }
    //return false;
    }
    else //associated with if eval loop i think
    {
    return true;
    }//if eval statement
    }//for loop j
    }//for loop i
    }//function name
    </script>

    Dan

  10. #10
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is it your trying to do and could you provide the form so i can see what its doing

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i cannot add the text file so you cannot see the source. I thought the above posting described what I was trying to do. My problem is that the code will verify that if a radio button is selected, for only one dropdown field the JS code will verify that a 9** is the last item in the list. I need to do this JS for any number if fields. I use a for loop to get the file name. that is the numericalts + 1 field.

    I don't know if this helps, but posting a .jpg of my page may not really help.

    sorry if this post does not explain the other posts.

    Dan

  12. #12
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still not sure what you actually want it to do as it seems very obscure

    in the previous post you wanted
    multiple text fields related
    and now you want a dropdown?

    also it apears as if your looking to use check box's and not radio buttons if you testing if more than one is checked.

    as you can i see im really confused at what your trying to do thats why i asked for a copy of your form lol

    ps i cleaned up the code for people to see what your trying to do

    PHP Code:

    <form name="receipt">

        <
    input type="text" name="NumericAlts1">
        <
    input type="radio" name="YIELDCODE" checked>
        <
    input type="radio" name="YIELDCODE">
        <
    input type="radio" name="YIELDCODE">

    </
    form>



    <
    script language="javascript">

    var 
    num1;
    function 
    alt900_check()
    {
        var 
    startIndexendIndex;
        
        
    msg=     "Since you selected a Yield Code of Alt900, the string must have a 9** value.\n";
        
    msg+=     "The last number does not have a 9 as the first digit.\n";
        
    msg+=     "It is not a proper Alt900 String."

        for (
    i=1;i<num+1;i++) 
        { 
            var 
    strNum = eval("document.receipt.NumericAlts"+i+".value");
     
            
    startIndex1     strNum.lastIndexOf(",");
            
    startIndex     startIndex1 1
            
    endIndex     strNum.length
            
    answer         strNum.substring(startIndex,endIndex);

            
    alert ('startIndex1 = ' startIndex1 '\n\n' 'startIndex = ' startIndex '\n\n' 'endIndex = ' endIndex '\n\n' 'answer = ' answer)
            
                for (
    02j++) 
                { 
                    if (eval(
    "document.forms[0].YIELDCODE[" "].checked")) 
                    { 
                        if( 
    answer.charAt(1) == "9"
                        { 
                            
    //return true; 
                        

                        else 
                        { 
                            
    alert(msg); 
                            
    // return false; 
                        

                        
    //return false; 
                    

                    else 
    //associated with if eval loop i think 
                    

                        return 
    true
                    }
    //if eval statement 
                
    }//for loop j 
        
    }//for loop i 
    }//function name 

    alt900_check()

    </script> 
    Last edited by Andrew-J2000; Apr 8, 2002 at 11:06.

  13. #13
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks for the help. When you responded I did some more studying of my code and compared it to other JS I have on my Cold Fusion pages and came up with a solution.
    I will look at your code and see if it will help me also.
    What I am trying to do is not the easiest think to explain. It would be easier to show through the code, that is why I don't understand why I cannot attatch a text file.

    Thanks

    Dan

  14. #14
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have posted waaaaaaaay too much stuff thinking I got results. I have not got results. here is my lastest delima:
    How do I find out the value of a radio button?
    In the following code, the line:
    var ycode = eval("document.forms[0].YIELDCODE" + "[" + j + "].checked")
    is inside a loop cause I thought that would get me what I needed. It gets me both codes for the yieldcode radio button. I only need the value that is checked.

    Then I need to have this whole code work for multiple dropdown boxes. I had an idea, but it does not work well. If the user selects the bad radio button option, the JS should look to see if the user selected the string out of the dropdown with a 9** on the end. if the user selects the good radio button, then the page submits the way it is.
    This needs to be done for multiple dropdowns...id the use of the num=form.weapon_count variable

    can someone help me?
    PCMOVER...you have understood my code so far, what about after this explanation?

    dan

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forgot to post the code:

    <script language="javascript">
    var num= <cfoutput>#form.weapon_count#</cfoutput>;
    function alt900_check(){
    var startIndex, endIndex;
    var answer = "";
    var msg = "Since you selected a Yield Code of Alt900, the string must have a 9** value.\nThe last number does not have a 9 as the first digit.\nIt is not a proper Alt900 String.";

    for (i=1;i<num+1;i++)
    {
    var strNum = eval("document.receipt.NumericAlts"+i+".value");
    alert(strNum);
    var compCond = eval("document.receipt.comp_condition"+i+".value");
    alert(compCond);
    startIndex1 = strNum.lastIndexOf(",");
    startIndex = startIndex1 + 1;
    endIndex = strNum.length;
    answer = strNum.substring(startIndex,endIndex);
    //alert(strNum);alert(startIndex1);alert(startIndex);alert(endIndex);alert(answer);
    for (j = 0; j < 2; j++)
    {
    //var ycode = eval("document.forms[0].YIELDCODE" + "[" + j + "].checked")
    //alert(ycode);

    if (eval("document.forms[0].YIELDCODE" + "[" + j + "].checked"))
    //if (ycode = "FALSE");
    {
    //msg += "\nNumericAlts"+i;
    if( answer.charAt(1) == "9"){
    msg += "\nNumericAlts"+i;
    }
    }
    }
    }
    if( msg != "Since you selected a Yield Code of Alt900, the string must have a 9** value.\nThe last number does not have a 9 as the first digit.\nIt is not a proper Alt900 String.")
    {
    //return true;
    //}
    //else
    //{
    alert(msg);
    return false;
    //}
    //return false;
    }
    else //associated with if eval loop i think
    {
    return true;
    }//if eval statement
    //}//for loop j
    //}//for loop i
    }//function name
    </script>


Bookmarks

Posting Permissions

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