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

    Problem with onblur & function

    Hi all,

    Not sure if this should be in this thread as is my first post 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

    Here is the code:
    PHP 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:
    PHP Code:
        <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> 

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    concatenation in javascript is done with +, not .
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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

  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry different error now - Object doesn't support this property or method.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Okay I've played around with the code and here's what I have.

    PHP Code:
        <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:
    PHP Code:
    <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:
    PHP Code:
    <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.


  •  

    Posting Permissions

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