/    Sign up×
Community /Pin to ProfileBookmark

can u help a starter? browser compatability

Hi – just started to learn Javascript so please my noviceyness (!)…

Have written following script for user to enter certain values (for a lifestyle questionnaire) and returns sum of a range of questions.

My test code (below) works on my IE but not in other browsers – any suggestions? Sorry if this stupidly obvious. Many thanks in advance

pete

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

<script language=”JavaScript” type=”text/javascript”>
function qcheck(x)
{
var answer = x;
if ((answer.value < 0) || (answer.value > 5) || (isNaN(answer.value)== true))
{
alert(“please enter valid input”);
}
}

function result()
// adds up the answers entered by user and displays result
{
var answer = parseInt(document.spq.q1.value) + parseInt(document.spq.q2.value) + parseInt(document.spq.q3.value);
var answer2 = parseInt(document.spq.q4.value) + parseInt(document.spq.q5.value) + parseInt(document.spq.q6.value);
document.write(answer + ” result1 (ques 1 to 3 added together)”);
document.write(answer2 + ” result2 (ques 4 to 6 added together)”);
}
</script>

</head>

<body>
<form name=”spq” id=”spq”>
<p>
<input name=”q1″ type=”text” id=”q1″ size=”3″ onChange=”qcheck(document.spq.q1)”>
q1 </p>
<p>
<input name=”q2″ type=”text” id=”q2″ size=”3″ onChange=”qcheck(document.spq.q2)”>
q2</p>
<p>
<input name=”q3″ type=”text” id=”q3″ size=”3″ onChange=”qcheck(document.spq.q3)”>
q3 </p>
<p>
<input name=”q4″ type=”text” id=”q4″ size=”3″ onChange=”qcheck(document.spq.q3)”>
q4</p>
<p>
<input name=”q5″ type=”text” id=”q5″ size=”3″ onChange=”qcheck(document.spq.q4)”>
q5</p>
<p>
<input name=”q6″ type=”text” id=”q6″ size=”3″ onChange=”qcheck(document.spq.q6)”>
q6 </p>
<p>
<input type=”submit” name=”Submit” value=”Submit” onClick=”result()”>
</p>
</form>

</body>
</html>

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonJun 22.2004 — Does this make it work?var answer = parseInt(x.value);
Copy linkTweet thisAlerts:
@peterj1927authorJun 22.2004 — nope that buggers up the validation check in IE
Copy linkTweet thisAlerts:
@David_HarrisonJun 22.2004 — Sorry, didn't read the script properly, try this:var answer = x.value.replace(/D/g,"");
if (parseInt(answer)&lt;0 || parseInt(answer)&gt;5 || answer=="")
I'm going offline now, so if that doesn't work it'll be a while until I get back on.
Copy linkTweet thisAlerts:
@peterj1927authorJun 22.2004 — works on my IE but carshes a friends IE and no result returned on his Safari browser.

doin my ed in

?
Copy linkTweet thisAlerts:
@David_HarrisonJun 22.2004 — I reworked the script.

[upl-file uuid=9771030d-cce9-416f-b9c9-196d9398371d size=3kB]peterj1927.txt[/upl-file]
Copy linkTweet thisAlerts:
@peterj1927authorJun 22.2004 — Bingo - nice one mate - I owe you a pint there - big time. Did you learn JScript from any particular source? I've got the basics but the finickity details do me ed in.

thnx again

Pete
Copy linkTweet thisAlerts:
@David_HarrisonJun 22.2004 — [i]Originally posted by peterj1927 [/i]

[B]Did you learn JScript from any particular source?[/b][/quote]
Yeah, I learned it all here. (JavaScript by the way, JScript is a microsoft version).
Copy linkTweet thisAlerts:
@David_HarrisonJun 22.2004 — I should point out that you can't use document.write after the page has loaded, if you do then it will replace the entire source code. That's why I created text nodes to dynamically write the text to the page.

Some people use .innerHTML for writing stuff into the page, but it's invalid accordnig to the W3C so future support for it is not guaranteed.
Copy linkTweet thisAlerts:
@peterj1927authorJul 20.2004 — Hi again - any chance you could point me in the direction of how to send the results to an email addy?

many thanks

Pete
Copy linkTweet thisAlerts:
@David_HarrisonJul 20.2004 — In theory you can do this:&lt;form action="mailto:[email protected]"&gt;In practice you cannot, IE messes up, users may not have the mail programs configired correctly (I don't even use a main program).

So the only actual way to send it over email would be to use server-side scripting. If you have a server-side language available then ask how to send an email using it in the appropriate forum.
Copy linkTweet thisAlerts:
@peterj1927authorJul 21.2004 — so what about sending the result of a function that calculates from a form? would maito work (in theory )

so for example I want to send the result of food where :

food = parseInt(document.spq.q10.value) + parseInt(document.spq.q23.value) + parseInt(document.spq.q44.value) +

parseInt(document.spq.q50.value) + parseInt(document.spq.q71.value) + parseInt(document.spq.q85.value) +

parseInt(document.spq.q95.value) + parseInt(document.spq.q113.value) + parseInt(document.spq.q116.value) +

parseInt(document.spq.q138.value) ;
Copy linkTweet thisAlerts:
@David_HarrisonJul 21.2004 — Yeah in theory, mailto: should work, but it doesn't. Not only does IE mess up sending things in the body of thr email, but I don't use a program to get my emails, I go to my email providers online website to send and receive emails.

There's no way that you can take me to their site, log me in, compose mail and then submit it. You'll have to use a server-side script to send emails.
Copy linkTweet thisAlerts:
@peterj1927authorJul 21.2004 — Right I'm at the end of the spectrum of my knowledge. Would you be interested in a bit of work sorting this out? Do you do server side scripting?

Have a look at the questionaiir at www.in2ict.co.uk/quest

What we want to do is get the results emailed as well as displayed with a name, address and email of person doing the questionairre too.

Interested? What would you charge for this?
Copy linkTweet thisAlerts:
@David_HarrisonJul 21.2004 — [i]Originally posted by peterj1927 [/i]

[B]Interested?[/B][/QUOTE]
Well it depends in what language, I'm pretty confident that I could do it with PHP and maybe ASP, but if it's anything else then I won't stand a cat in hell's chance.[i]Originally posted by peterj1927 [/i]

[B]What would you charge for this?[/B][/QUOTE]
Free, as always. ?
×

Success!

Help @peterj1927 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...