SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard bronze trophy cydewaze's Avatar
    Join Date
    Jan 2006
    Location
    Merry Land, USA
    Posts
    1,096
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    inserting values from other fields.

    I have a form that I use to populate our office's staff directory, and one of the form fields is the staff member's email address.

    The email address for everyone is firstname.lastname@ourdomain.com, although there are a few rare exceptions to this rule (like when we have two people with the same name, etc) so I can't really make the email address self-generate in the database.

    But what I would like to do is have a feature where once you fill in the member's first and last name, clicking on the email address field (or even a button next to it) grabs the firstname and lastname, adds a dot in between, and slaps the @domain.com on the end.

    So far I have the following script that adds the @domain.com, but I don't know how to fetch the names from the other fields.

    Code JavaScript:
    function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
    	myField.focus();
    	sel = document.selection.createRange();
    	sel.text = myValue;
    	}
    //MOZILLA/NETSCAPE support
    	else if (myField.selectionStart || myField.selectionStart == '0') {
    		var startPos = myField.selectionStart;
    		var endPos = myField.selectionEnd;
    		myField.value = myField.value.substring(0, startPos)
    		+ myValue
    		+ myField.value.substring(endPos, myField.value.length);
    	} else {
    	myField.value += myValue;
    	}
    }

    and

    Code HTML4Strict:
    <cfinput name="email" onFocus="insertAtCursor(document.editstaff.email, '@domain.com')" />

    Any ideas?

  2. #2
    SitePoint Wizard bronze trophy cydewaze's Avatar
    Join Date
    Jan 2006
    Location
    Merry Land, USA
    Posts
    1,096
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Woohoo! Trial & Error (+ google) > *

    Got it to work using this:

    Code HTML4Strict:
    <cfinput name="email" onFocus="insertAtCursor(document.editstaff.email, document.getElementById('name').value + '.' + document.getElementById('last_name').value + '@domain.com')" />


Bookmarks

Posting Permissions

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