Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Concatenate two html fields into one


  • Please log in to reply

#31
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
ScHwErV,

I was able to get your html and scripts working in IE, Firefox, and Opera by doing the following:
Possibly due to the file structure I was using, the script files weren't loading. I changed the script tags to reference relative paths to the html page, from:
<script language="JavaScript" src="/admin/javascript/combine_lastfirst.js"></script>
To:
<script language="JavaScript" src="../javascript/combine_lastfirst.js"></script>

Change comblf() function to the following, explicitly:
function comblf()
	{
		var last = document.forms[0].elements['[01]Last_Name'].value;
		var first = document.forms[0].elements['[01]First_Name'].value;
		if(last.length > 1 && first.length > 1)
	{
	document.forms[0].elements['[01]LastFirst'].value = last + ', ' + first;
	}
}
As you can see, the element id's will not need to be used at all, so can be eliminated from the first, last, and lastfirst fields.

Name field lines can be changed as follows:
First and last:
<td style="width: 265px"><input type="text" name="[01]First_Name" value="" size="15" onkeyup="comblf()" />  <input type="text" name="[01]Last_Name" value="" size="20" onkeyup="comblf()" /></td>
LastFirst:
<input type="hidden" name="[01]LastFirst" value="" style="width: 228px"  /></td>

Test script I used in the address bar after filling out the first and last name to display the combined field:
javascript:alert(document.forms[0].elements['[01]LastFirst'].value);

Let me know if you have any problems. The function must be exactly as I have listed it, referencing the element names, rather than the id's.
  • 0

Advertisements


#32
ScHwErV

ScHwErV

    Member 5k

  • Topic Starter
  • Retired Staff
  • 21,285 posts
  • MVP
I didn't hardly have time to look at it today as so many other things were happening. I did however change things as you recommended and it still did not work. I haven't had time to troubleshoot it yet, these are just preliminary results.

The change to the relative paths should not be necessary. Using the exact same paths, but with the ID elements, the script loads fine. I will try that part of your suggestions tomorrow, Ill even try it with the JS in the head rather than the outside file. Its all part of the troubleshooting process. However I just don't think that will be part of the problem.
  • 0

#33
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
OK, if you are still having problems after changing the paths, could you send me what you have again? That way I can help troubleshoot.
  • 0

#34
ScHwErV

ScHwErV

    Member 5k

  • Topic Starter
  • Retired Staff
  • 21,285 posts
  • MVP
I verified it multiple different ways. When the script you gave me is sitting in a folder on my desktop, it works great. As soon as I put it on the webserver, it breaks. Every single time. No matter what I do with the javascript. Ive even placed it directly into the head of the html (the old fashioned way) and it didn't work (ruling out a path-related issue).
  • 0

#35
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
I just tried it on an intranet and internet web server, worked just fine on both (testing with IE/Firefox/Opera with each). You sure it isn't something with your server? I'm going to send you the files back that I used to test.
  • 0

#36
ScHwErV

ScHwErV

    Member 5k

  • Topic Starter
  • Retired Staff
  • 21,285 posts
  • MVP
I thought about it possibly being something with the server, but using the ID elements on the server, everything functions as it should.
  • 0

#37
ScHwErV

ScHwErV

    Member 5k

  • Topic Starter
  • Retired Staff
  • 21,285 posts
  • MVP
Not saying that isnt it, but it just seems odd that the same script, same paths, same html and it doesn't work. It could be that the server is translating the field names server-side, but that would be strange.
  • 0

#38
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
That is totally strange. The server must be doing something weird, but I'm not quite sure what it could be. Would it be caching an old version of the js files? Have you tried accessing the page from a different system?

If you want to use the ID solution, document.getElementById('element id').value would probably be the best method to use to get/set the value of an element based on its id attribute.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP