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.
Results 1 to 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question Adding & removing values from hidden field

    Hello,
    I've got several checkbox on a page, I need to be able to added and remove the values of the check box to and from a hidden text field in another form on the same page, but I'm having some issues with the indexOf function.

    my code so far:
    PHP Code:
    function AddOrderID(numOrderID){

        var 
    strHidden document.RegForm.ItemIDs
        
    if(strHidden.indexOf(numOrderID) == 0){
            
    strHidden.value strHidden.replace(/' + numOrderID + '/, "")
        } else {
            if(
    strHidden.value !== ""){
                
    strHidden.value strHidden.value "," numOrderID;
            } else {
                
    strHidden.value numOrderID;
            }
        }

    I'm not sure what i'm doing wrong here, i've searched good, and it *looks* like i'm using correctly, but i keep getting an error while trying to execute the script: "Object doesn't support this property or method".

    any help would be great,

    thanks in advance for your time!
    -Ken

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, I've cut down the code a bit, and found that i needed to add ".value" to my object calls. that fixed the errors,
    but still i can't seem to remove the values from the hidden field, I can only added them.

    my code:
    PHP Code:
    function AddOrder(numOrderID){

        var 
    strHidden document.RegForm.ItemIDs;
        if(
    strHidden.value.indexOf(numOrderID ',') > 0){
            
    strHidden.value strHidden.value.replace(/' + numOrderID + '/, "");
        } else {
            
    strHidden.value strHidden.value numOrderID ',';
        }

    any ideas?

    thanks again for your time!
    -Ken

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    oh, i've figured it all out,

    PHP Code:
    function AddOrder(numOrderID){

        var 
    strHidden document.RegForm.ItemIDs;
        if(
    strHidden.value.indexOf(numOrderID ',') == || strHidden.value.indexOf(numOrderID ',') > 0){
            
    strHidden.value strHidden.value.replace(numOrderID ','"");
        } else {
            
    strHidden.value strHidden.value numOrderID ',';
        }

    all the examples i used were for static data, sorry for being such a newb! ;-)

    -Ken

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure exactly what you are doing, but try changing the test to:

    if(strHidden.value.indexOf(numOrderID + ',') >= 0){

    since indexOf returns -1 on failure, not 0.

    david_kw

    Edit: ha! you beat me to it. :)
    Last edited by david_kw; 01-08-2007 at 07:21 PM.


  •  

    Posting Permissions

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