/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Can anybody spot an error with this script?

Hi,
can anybody spot an error with this script
It is the second load script preceded by the seconf <script type=”text/javascript”> tag.

[CODE]<script type=”text/javascript”>
function type_select2(val){
var textbox = document.forms[’emails’].elements[‘description’];
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is “;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is “;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is “;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is Won’t post to BFPO”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is Won’t post to BFPO due to cost!”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is “;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is BFPO do not allow Omega to deliver to them
You could still email them howver to get them to put pressure on BFPO.”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is Could not purchase £1000 worth of gift cards asIkea refused to recognise the BFPO 17 address”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘[email protected]’)
{
textbox.value = “The problem with this company is Do not deliver to BFPO addresses”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
}
</script>[/CODE]

If not, does it matter that the script is directly after this script, both scripts are in the <head> tag and I cannot put them both under the same script tags as the one above is dynamically generated by php and when I try to put the php in the javascript it doesnt recognise the php.

[CODE]
script type=”text/javascript”>
function type_select(val){
var textbox = document.forms[’emails’].elements[‘description’];
if (val == ‘0’)
{
textbox.value = “Please select a company in the box above.”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘1’)
{
textbox.value = “Dear Sirs/Madam,nnI am emailing you in order to enquire as to the reason that you do not deliver to BFPO addresses.nnThere are literally hundreds of thousands of servicemen and women stationed outside the UK mainland. This of course equates to hundreds of thousands of potential customers that you are alianating. With many companies there are a number of reasons that they do not deliver to BFPO addresses these range from issues such as the courier of there choice not being allowed to deliver to Mill Hill to the address look-up software such as QAS not recognising BFPO addresses in the postcode field. Often, all that is required for campanies to accept BFPO addresses is a small change in their system. nnThe BFPO Campaign is currently in touch with many organisations of all backgrounds in an attempt to get people to work together for the good of our Armed Forces.nnIf you have any queries then please contact the BFPO Campaign who will be able to answer and questions that you may have, alternatively you can contact me direct by replying to this email.nnYours Sincerily,n”The BFPO Campaign” Supporter”;
document.getElementById(‘div1’).style.display = “none”;
document.getElementById(‘div2’).style.display = “none”;
}
if (val == ‘2’ )
{
textbox.value = “Dear Sirs/Madam,nnI am emailing you to complain about the fact that you do not deliver to BFPO addresses.nnEvery day there are thousands of servicemen and women risking there lives in various operation theatres in countrries spanning the globe. Whilst they are away they are our savious and heroes, and yet once they return to their units they find it difficult to get have goods delivered, obtain services and even have access to the most basic of facilities such as opening bank accounts.nnThis is due to the fact that they use BFPO addresses instead of a postcode, although all post automatically goes to an address in Mill Hill, London, many companies such as yourselves refuse to deliver to them. This can be due to a number of factors such as address look-up software, the couriers not being alowed to deliver to Mill Hill or even a small change is required to the companies system in order to recognise BFPO addresses.nThere are literally hundreds of thousands of servicemen and women stationed outside the UK mainland. This of course equates to hundreds of thousands of potential customers that you are alianating.nn”The BFPO Campaign” is currently in touch with many organisations of all backgrounds in an attempt to get people to work together for the good of our Armed Forces.nIf you have any queries then please contact the BFPO Campaign who will be able to answer and questions that you may have, alternatively you can contact me direct by replying to this email.nnYours Faithfully,n”The BFPO Campaign” Supporter”;
document.getElementById(‘div1’).style.display = “block”;
document.getElementById(‘div2’).style.display = “block”;
}
if (val == ‘3’ )
{
textbox.value = “”;
document.getElementById(‘div1’).style.display = “none”;
document.getElementById(‘div2’).style.display = “none”;
}
}
function validate1(){
var digits=”0123456789″
var temp
if (document.emails.id.value==””) {
alert(“Please choose a company”)
return false
}
if (document.emails.description.value==””) {
alert(“Please enter a message”)
return false
}
if (document.emails.subject.value==””) {
alert(“Please enter a subject”)
return false
}
if (document.emails.name.value==””) {
alert(“Please enter your name”)
return false
}
if (document.emails.email.value==””) {
alert(“Please enter an email address”)
return false
}
return true
}
function validate2(){
var digits=”0123456789″
var temp
if (document.friend.yourName.value==””) {
alert(“Please enter your name”)
return false
}
if (document.friend.yourEmail.value==””) {
alert(“Please enter your email address”)
return false
}
if (document.friend.friendsName.value==””) {
alert(“Please enter your friends name”)
return false
}
if (document.friend.friendsEmail.value==””) {
alert(“Please enter your friends email address”)
return false
}
if (document.friend.message.value==””) {
alert(“Please type in a message to send to your friend”)
return false
}
return true
}
</script>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterAug 21.2006 — In JavaScript , unlike PHP, strings cannot span multiple lines however can still contain newline characters.

In otherwords convert the following:
<i>
</i>if (val == '[email protected]')
{
textbox.value = "The problem with this company is BFPO do not allow Omega to deliver to them
You could still email them howver to get them to put pressure on BFPO.";
document.getElementById('div1').style.display = "block";
document.getElementById('div2').style.display = "block";
}

into:
<i>
</i>if (val == '[email protected]')
{
textbox.value = "The problem with this company is BFPO do not allow Omega to deliver to themnYou could still email them howver to get them to put pressure on BFPO.";
document.getElementById('div1').style.display = "block";
document.getElementById('div2').style.display = "block";
}

There of coarse is more than one to get a job done. The newline is treated as a character and can be escaped just like any other character if you add a in front of the new line:
<i>
</i>if (val == '[email protected]')
{
textbox.value = "The problem with this company is BFPO do not allow Omega to deliver to them
You could still email them howver to get them to put pressure on BFPO.";
document.getElementById('div1').style.display = "block";
document.getElementById('div2').style.display = "block";
}
Copy linkTweet thisAlerts:
@postedoverseasauthorAug 21.2006 — Fantasic, worked a treat I'll keep that in mind.

As you can tell, I am new to javascript and I'm picking up bits of it as I go,

Thanks agin,

John
Copy linkTweet thisAlerts:
@UltimaterAug 21.2006 — One last note about putting a backslash before a newline is that it won't be added to the string.

In otherwords the following two are equivalents:
<i>
</i>alert("a
b")
alert("a"+
"b")

if you want an actual new line in there you'd need to do:
<i>
</i>alert("an
b")
alert("an"+
"b")


Note: I haven't tried this on any other OS than Windows and the behaviors between the OS may vary because Windows treats newlines as rn and macs as r and linux as n. Then again, it's possible they all treat it the same way -- I'm feeling too lazy to research. Best just stick with n's.
×

Success!

Help @postedoverseas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...