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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing parameter in function

    Hi - I've tried passing this hundreds of different ways without effect. In a nutshell, I have an HTML page that is generated dynamically from db and has form elements with the same name plus the numeric ID from the db tacked on the end to make the form elements individual.

    With JS, I've been able to determine which form elements need to be processed. Where I'm falling short is when I try to validate those form elements, my code breaks down:


    function addrsvp(str)
    {
    var event_id = +str;
    if (Record_Validator(''+event_id+'') == true)
    {
    document.frm.action = "?action=addrsvp&id="+event_id
    document.frm.method = "post"
    document.frm.submit()
    }
    }


    // This part works fine - with the Record_Validator, just using the alert box, I've verified "ev_id" is being passed correctly. Where it breaks down is the if statement adding the ev_id to the end of "first" - tried everything I could find:

    function Record_Validator(strg)
    {
    var ev_id = +strg
    if (document.frm.first+ev_id+.value == "")
    {
    alert(''+ev_id+'');
    return (false);
    }

    return true;
    }

    Any suggestions will be tremendously appreciated.

    Chase

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Would this work at all?

    Code:
    function Record_Validator(strg)
    {
    var ev_id = +strg;
    fieldname='first'+ev_id;
    if (document.frm.fieldname.value == "")
    {
    alert(''+ev_id+'');
    return (false);
    }
    Also: just so you know, on your alert: alert(''+ev_id+'');, you can just put alert(ev_id);, and when you call ev_id you can just put var ev_id = strg;
    Last edited by binaryWeapon; 05-07-2008 at 01:13 AM. Reason: Sidenote

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by binaryWeapon View Post
    Would this work at all?

    [code]
    function Record_Validator(strg)
    {
    var ev_id = +strg;
    fieldname='first'+ev_id;
    if (document.frm.fieldname.value == "")

    Thanks for the overall tips. Much appreciated.

    The above modification gives me the error "document.frm.fieldname.value is null or not an object"

    Really appreciate the help.

    Chase

  • #4
    New to the CF scene
    Join Date
    May 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW - with document.write - I was able to verify that "fieldname = "first"+ev_id " returned the desired fieldname. Still can't figure out integrate that to work correctly -- document.frm.fieldname.value == "" ....

    Chase

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    OK this might not work at all, I would just suggest trying putting your javascript below your form if thats possible. I don't know why but sometimes when I had my form after my javascript it wouldn't recognize the form or the fields.

    This might not be the problem, but I wanted to mention it.

    GL

  • #6
    New to the CF scene
    Join Date
    May 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks again GL. If I hardcode it to what I know will be one of the form fields - document.frm.first6.value == "" - then all is cool and works as it should.

    I guess I maybe should have thought of asking this earlier but should it make a difference that the parameter is always numeric?

    Chase

  • #7
    New to the CF scene
    Join Date
    May 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Finally found something that worked:

    if (document.getElementById("first" + strg).value == "")

    Thanks again for all the help. You're very kind to take the time.

    Chase


  •  

    Posting Permissions

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