473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Get FirstName, LastName and EmailAddress from URL

Hi

I am getting an Object Expected error when using the following script. Can
anyone see any syntax error?

<script>

aTemp=location.href.split("?");

if (isnull(aTemp[1])=false)
{
document.forms[0].MyFirstName.value=aTemp[1];
}
if (isnull(aTemp[2])=false)
{
document.forms[0].MyLastName.value=aTemp[2];
}
if (isnull(aTemp[3])=false)
{
document.forms[0].MyEmailAddress.value=aTemp[3];
}
</script>
Jul 23 '05 #1
6 4298
var aMayBe, bSplit, iUseFul

aMayBe = location.href.split("?");

bSplit = iUseFul = aMayBe.length

if(bSplit && iUseFul > 1){

aMayBe.shift()

for(var i = 0 ; i < aMayBe.length ; i++)
document.forms[0].elements[i].value=aMayBe[i];

}

You need more than 1 array values (those from the right site of the split).
So you get rid of the first.
Now let it iterate over you form fields by index.
Until you drop, or your PC.

Of course this can be shortened.

Also I have never seen a "isnull" in javascript?

If it is not home grown,

use attribute type="text/javascript"

<script type="text/javascript">

"Mark 123" <no**@none.com> wrote in message
news:y0********************@news.xtra.co.nz...
Hi

I am getting an Object Expected error when using the following script. Can
anyone see any syntax error?

<script>

aTemp=location.href.split("?");

if (isnull(aTemp[1])=false)
{
document.forms[0].MyFirstName.value=aTemp[1];
}
if (isnull(aTemp[2])=false)
{
document.forms[0].MyLastName.value=aTemp[2];
}
if (isnull(aTemp[3])=false)
{
document.forms[0].MyEmailAddress.value=aTemp[3];
}
</script>


Jul 23 '05 #2
Mark 123 wrote:
Hi

I am getting an Object Expected error when using the following script. Can
anyone see any syntax error?

<script>
The type attribute is required:

<script type="text/javascript">

aTemp=location.href.split("?");

if (isnull(aTemp[1])=false) --------^-------------^

I think you're after Douglas Crockfords 'isNull()'.

<URL:http://www.crockford.com/javascript/remedial.html>

isNull() (if you implement it) returns 'true' if the expression is
null, so you have the 'sense' of the comparison wrong.

But ... you have an assignment instead of a comparison - gosh, all that
in just one line! :-)

If you want the code to execute if aTemp[1] *is not* null, then:

if ( aTemp[1] ) {
// do stuff
}

will do the trick.
{
document.forms[0].MyFirstName.value=aTemp[1];
}
if (isnull(aTemp[2])=false)
{
document.forms[0].MyLastName.value=aTemp[2];
}
if (isnull(aTemp[3])=false)
{
document.forms[0].MyEmailAddress.value=aTemp[3];
}
I would nest the ifs so that if one fails, subsequent ifs are skipped
(and keep a reference to the from for brevity):

if ( aTemp[1] ) {
var f = document.forms[0];
f.MyFirstName.value = aTemp[1];

if ( aTemp[2] ) {
f.MyLastName.value = aTemp[2];

if ( aTemp[3] ) {
f.MyEmailAddress.value = aTemp[3];
}
}
}

But even then you are making assumptions that the values of aTemp are
suitable - hopefully you have don some testing or validation of the
values before using them.
</script>

--
Rob
Jul 23 '05 #3
commercial wrote on 04 jul 2005 in comp.lang.javascript:
var aMayBe, bSplit, iUseFul

aMayBe = location.href.split("?");

bSplit = iUseFul = aMayBe.length

if(bSplit && iUseFul > 1){

aMayBe.shift()

for(var i = 0 ; i < aMayBe.length ; i++)
document.forms[0].elements[i].value=aMayBe[i];

}

You need more than 1 array values (those from the right site of the
split). So you get rid of the first.
Now let it iterate over you form fields by index.
Until you drop, or your PC.

Of course this can be shortened.


[not sending HTML on usenet would be best shortening ;-)]

aMayBe = location.href.split("?");
for (var i = 1 ; i < aMayBe.length ; i++)
document.forms[0].elements[i].value = aMayBe[i];

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #4
Evertjan. wrote on 04 jul 2005 in comp.lang.javascript:
aMayBe = location.href.split("?");
for (var i = 1 ; i < aMayBe.length ; i++)
document.forms[0].elements[i].value = aMayBe[i];


However, I think this is ment:

mySplit = location.href.split('?');
if (mySplit.length>1){
aMayBe = mySplit.split('&')
for (var i = 0 ; i < aMayBe.length ; i++)
document.forms[0].elements[i].value = aMayBe[i];
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #5
Mark 123 wrote:
Hi

I am getting an Object Expected error when using the following script. Can
anyone see any syntax error?

<script>

aTemp=location.href.split("?");

if (isnull(aTemp[1])=false)
{
document.forms[0].MyFirstName.value=aTemp[1];
}
if (isnull(aTemp[2])=false)
{
document.forms[0].MyLastName.value=aTemp[2];
}
if (isnull(aTemp[3])=false)
{
document.forms[0].MyEmailAddress.value=aTemp[3];
}
</script>


Two, actually.
1. isnull is undefined. Try using
if( aTemp != null )

2. Cannot assign to function result. Assuming you made a function
called isnull, you would want to use
isnull(aTemp[n])==false
or
!isnull(aTemp[n])
To get the boolean you expect in your if() statements.
I also see what is probably a logical problem:
For the URL: http://my.example.com/foo.htm?name=value
aTemp will be an array of two values:
aTemp = [
'http://my.example.com/foo.htm',
'name=value'
];
On the other hand, for a (malformed?) URL:
http://my.example.com/foo.htm?avalue...alue?a3rdvalue
then
aTemp = [
'http://my.example.com/foo.htm',
'avalue',
'anothervalue',
'a3rdvalue'
];

Maybe that's what you intended, but isn't it a bit strange?

It would seem better to split location.search on ampersands (into
name/value pairs), then split each result on equal signs (into
individual names and values), then unescape each of those results...
That way you could deal with:

http://my.example.com/foo.htm?MyFirs...stName=Hahn%7e

i.e. this code...
if( aTemp = location.search.split('&')[1] ) {
aTemp = aTemp.split( '&' );

for( c = 0; c < aTemp.length; c++ ) {
aTemp[c] = aTemp[c].split( '=' );

document.forms[0].elements[ unescape( aTemp[c][0] ) ] =
unescape( aTemp[c][1] );

}
}

As a most rough example. It is not the most robust bit of work in the
world (it doesn't handle spaces well), but it can handle very simple
jobs.

Jul 23 '05 #6
Christopher J. Hahn wrote:
[snip]
It would seem better to split location.search on ampersands (into
name/value pairs), then split each result on equal signs (into
individual names and values), then unescape each of those results...
That way you could deal with:

http://my.example.com/foo.htm?MyFirs...stName=Hahn%7e

i.e. this code...
if( aTemp = location.search.split('&')[1] ) {
aTemp = aTemp.split( '&' );

for( c = 0; c < aTemp.length; c++ ) {
aTemp[c] = aTemp[c].split( '=' );

document.forms[0].elements[ unescape( aTemp[c][0] ) ] =
unescape( aTemp[c][1] );

}
}

As a most rough example. It is not the most robust bit of work in the
world (it doesn't handle spaces well), but it can handle very simple
jobs.

This line
document.forms[0].elements[ unescape( aTemp[c][0] ) ] =
Should read
document.forms[0].elements[ unescape( aTemp[c][0] ) ].value =

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Victor Lokhmatov | last post by:
Hello Everyone, My company has asked me to put a company directory on our intranet site and I'm trying to use php to extract the users from our active directory server. I've got everything...
2
by: Leader | last post by:
HI, i got a problem while using StrConv function in sql server. My requirement is:- suppose in a name field i have "jhon smith" Now i want to run a sql which will give me the result like "Jhon...
5
by: Theresa Hancock via AccessMonster.com | last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this. -- Message posted...
1
by: Jean | last post by:
Hi everyone, Can someone please help me out here? I am finishing a project at my client, and they said that I could take a copy of the database I created home (i.e. so that I will support...
2
by: musicloverlch | last post by:
I used to have a function that would change data that came across as LASTNAME, FIRSTNAME MI to FirstName M. LastName with an update query. Does that sould familar to anyone? Thanks in advance,...
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
2
by: imani_technology_spam | last post by:
I'm sure you all have seen situations where a field has a combined name in the format of "Lastname, Firstname Middlename" and I've seen examples of parsing that type of field. But what happens...
0
by: avssiva | last post by:
I am doing one project . in that we are using smtp and pop3 mail servers sending and receving respectively. My problem is display USERNAME(LASTNAME OR FIRST NAME ) in the place of Sender email-id. ...
1
by: ramprakashjava | last post by:
hi , i hav this error while running this customerDetails.jsp <html:html> <head> <html:base/> </head> <body> <html:errors/> <html:form...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.