...

View Full Version : Problem with onblur & function



siggles
07-04-2007, 11:53 PM
Hi all,

Not sure if this should be in this thread as is my first post :confused: but here goes.

I have created a small address book built in PHP & MySQL. The following are snippets from my page named insert.php. This page inserts a record into the database - which is working fine but.....

On this page I have the following fields:
first_name - first name of contact
middle_name - middle name of contact
last_name - last name of contact
display_name - the name to be displayed on the main page of the address book (for thois who are unfamiliar check out Contacts in MS Outlook).

When a user enters the last name I want the display_name to default to first_name & last_name BUT I keep getting a stupid error saying "Object Expected". For the life of me I can't figure this out so please - HEEEEELLLP :( :( :confused: :confused: :confused:

Here is the code:

<label class="secondlabels">first name:</label><input type="text" name="first_name" size="50" class="requiredinput"/><br>
<label class="secondlabels">middle name:</label><input type="text" name="middle_name" size="50"/><br>
<label class="secondlabels">last name:</label><input type="text" name="last_name" size="50" class="requiredinput" onblur="func_display_name();"/><br>
<label class="secondlabels">display name:</label><input type="text" name="display_name" size="50" class="requiredinput"/><br>


and the function:

<script language="JavaScript">
function func_display_name() {
form=document.insert_contact
if (form.first_name.value=="" || form.last_name.value=="") {
form.display_name.value ="";
alert("You haven't entered a first name or last name. Please do this now.");
} else {
form.display_name.value = form.first_name.value . " " . form.last_name.value;
}
</script>

GJay
07-05-2007, 12:03 AM
concatenation in javascript is done with +, not .

siggles
07-05-2007, 12:21 AM
Duh - Thanks GJay,

But I've tried that and it's still doing giving the same error. I've also tried changing the last line in the function so it now reads:


<script language="JavaScript">
function func_display_name() {
form=document.insert_contact
if (form.first_name.value=="" || form.last_name.value=="") {
form.display_name.value ="";
alert("You haven't entered a first name or last name. Please do this now.");
} else {
form.display_name.value = form.first_name.value;
}
</script>

siggles
07-05-2007, 12:23 AM
Sorry different error now - Object doesn't support this property or method.

siggles
07-05-2007, 01:06 AM
Okay I've played around with the code and here's what I have.


<script language="JavaScript">
function func_display_name() {
form=document.insert_contact
if (form.first_name.value=="" || form.last_name.value=="") {
form.display_name.value ='';
alert("You haven't entered a first name or last name. Please do this now.")
} else {
form.display_name.value = form.first_name.value;
}
</script>

and:

<label class="secondlabels">first name:</label><input type="text" id="first_name" name="first_name" size="50" onblur="func_display_name()" class="requiredinput"/><br>
<label class="secondlabels">middle name:</label><input type="text" id="middle_name" name="middle_name" size="50"/><br>
<label class="secondlabels">last name:</label><input type="text" id="last_name" name="last_name" size="50" class="requiredinput" onblur="func_display_name()"/><br>
<label class="secondlabels">display name:</label><input type="text" id="display_name" name="display_name" size="50" class="requiredinput"/><br>


The error I'm getting is still - Object expected.

I've got a work around for now:

<label class="secondlabels">first name:</label><input type="text" id="first_name" name="first_name" size="50" onblur="if (display_name.value=''){display_name.value='';} else {display_name.value=first_name.value + ' ' + last_name.value}" class="requiredinput"/><br>
<label class="secondlabels">middle name:</label><input type="text" id="middle_name" name="middle_name" size="50"/><br>
<label class="secondlabels">last name:</label><input type="text" id="last_name" name="last_name" size="50" class="requiredinput" onblur="if (display_name.value=''){display_name.value='';} else {display_name.value=first_name.value + ' ' + last_name.value}"/><br>
<label class="secondlabels">display name:</label><input type="text" id="display_name" name="display_name" size="50" class="requiredinput"/><br>


but would prefer to use a function so if you can help please do so.

Cheers

Siggles.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum