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
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onchange with submit

    hi

    i have a form where i need to join fields from the form prior to submission to flow into a pdf form.


    here is the function
    PHP Code:
    <SCRIPT language='javascript' type='text/javascript'>
    function 
    joinna(formelemNamettl) {


    form.bname.value form.b_fname.value ' ' form.b_lname.value;

    }
    </script> 
    here is what the form input looks like
    PHP Code:
    <input class="left" onBlur="mark(this,'#ffffff','#000000')" name="b_fname" size="20" maxlength="40" onFocus="nextfield ='cb_fname'; mark(this,'#FFFF99','#0000FF')" value="<?php echo $row['b_fname'];?>" onChange="joinna(this.form,'b_fname','p1f6');">
    </span>
    <input class="left" onBlur="mark(this,'#ffffff','#000000')" name="b_lname" size="20" maxlength="40" onFocus="nextfield ='cb_fname'; mark(this,'#FFFF99','#0000FF')" value="<?php echo $row['b_lname'];?>" onChange="joinna(this.form,'b_lname','p1f6');">
    </span>
    and here is the calc field

    PHP Code:
    <input type="hidden" NAME="bname" value="" Size="7" onBlur="mark(this,'#ffffff','#000000')" onFocus="blur();document.smartform.bname.focus()" onChange="this.form.b_fname.value + this.form.b_lname.value; joinna(this.form,'field');" 
    this works fine IF i manually insert something new into the b_fname field. but lets say a user pulls the for to edit, and then makes no changes, "bname" will remain blank.

    what i want to do is call the function and/or force an 'onchange' or do whatever so bname is not left blank in the event the user submits w/o making any changes to the form

    tia

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Easy answer: Use PHP code to preload bname with what it should get if the user doe *not* make any changes. Do it in PHP instead of mucking with the JavaScript.

    ********

    I have to ask. You have:
    Code:
    function joinna(form, elemName, ttl) {
        form.bname.value = form.b_fname.value + ' ' + form.b_lname.value;
    }
    What in the world is the point of having (and passing!) the arguments elemName and ttl if you never use them in that function?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    LOL! Pardon me, but this is silly!
    Code:
    <input type="hidden" NAME="bname" value="" Size="7" 
           onBlur="mark(this,'#ffffff','#000000')" 
           onFocus="blur();document.smartform.bname.focus()"
           onChange="this.form.b_fname.value + this.form.b_lname.value; joinna(this.form,'field');" >
    A *HIDDEN* field can NEVER get an onblur or onfocus or onchange event via human interaction. And the size of a hidden field is MEANINGLESS!

    Kill all the useless code and do this:
    Code:
    <input type="hidden" NAME="bname" 
           value="<?php echo $row['b_fname'] . ' ' . $row['b_lname']; ?>" />
    so that the hidden field already has the default value if the user makes no changes.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, yes, of course, i copied and pasted from fields that were not hidden. all the extraneous code is superfluous

    as far as joining names using $row['b_fname'] . ' ' . $row['b_lname'], that might work so long as there is an entry in the DB or if there is no change to the fields on edit.

    but if there is a change, the question is how to put the two together as if it had been typed in to its own field


    ...

    if it were just a matter of pulling from the MySQL into the field i would not bother to post. the issue is the code i use to generate a PDF file and the field mapping issues in re the PDF document.

    the PDF has bname but the db is b_fname and b_lname

    the pdf code generates a fdf file that comes right from the html form and is independent of the DB, so if the field is not on the HTML form *with* the data joined, then when the fdf file is generated that will be missing and the name field on the pdf form will be ... blank

    what i want to do is make sure the fields get filled in even if there is no changes made, otherwise unless you literally click into the filed and make a change, there will be no data.

    that is what i am trying to fix

    thanks again
    Last edited by inosent; 05-16-2012 at 12:35 AM.

  • #5
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Easy answer: Use PHP code to preload bname with what it should get if the user doe *not* make any changes. Do it in PHP instead of mucking with the JavaScript.

    ********

    I have to ask. You have:
    Code:
    function joinna(form, elemName, ttl) {
        form.bname.value = form.b_fname.value + ' ' + form.b_lname.value;
    }
    What in the world is the point of having (and passing!) the arguments elemName and ttl if you never use them in that function?
    honestly, i didnt know. lots of times i take code that works and drop in my variables and leave the rest alone. its how i learn. but it looks like you are right, i did not need it, i just left "(form)" and it seems to work fine

    but the question i asked remains unanswered

    thanks for the tip!

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Quote Originally Posted by inosent View Post
    as far as joining names using $row['b_fname'] . ' ' . $row['b_lname'], that might work so long as there is an entry in the DB or if there is no change to the fields on edit.

    but if there is a change, the question is how to put the two together as if it had been typed in to its own field
    By leaving the other two fields as they are, with their onchange code in place.

    If there is no value in the DB, then there won't be any value in *any* of the fields, visible or hidden. If there are values, then both the visible fields and the hidden one get filled in. If there is a change, whether there are any values from the DB or not, then the fname and lname fields get concatenated and the combo *replaces* what was in the hidden field, no matter what.

    In short, you shouldn't need to change any field except the hidden one, and just change it to what I showed you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, i think i got it ... let me see

    thanks again


  •  

    Posting Permissions

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