...

View Full Version : onchange with submit



inosent
05-15-2012, 10:49 PM
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


<SCRIPT language='javascript' type='text/javascript'>
function joinna(form, elemName, ttl) {


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

}
</script>


here is what the form input looks like


<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



<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

Old Pedant
05-15-2012, 11:47 PM
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:


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?

Old Pedant
05-15-2012, 11:51 PM
LOL! Pardon me, but this is silly!


<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:


<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.

inosent
05-16-2012, 12:23 AM
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

inosent
05-16-2012, 12:28 AM
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:


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!

Old Pedant
05-16-2012, 12:58 AM
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.

inosent
05-16-2012, 01:38 AM
ok, i think i got it ... let me see

thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum