..." /> Question Anyone know html javascript (hybrid type) coding - Virtual Assistant Forums

Website Coding

Stuck on a line of code? Find resources and post your coding questions here.

Forum Sponsor (Advertise with us)
Reply
 
Thread Tools Display Modes
    #1 (permalink)  
Old 04-23-2012
RhondaHolscher's Avatar
RhondaHolscher RhondaHolscher is offline
Active Member
Company name: Rhonda's Virtual Office
 
Join Date: Feb 2010
Location: Cincinnati, OH, USA
Posts: 760
Blog Entries: 13
Send a message via Yahoo to RhondaHolscher
Follow this virtual assistant on Twitter Find this virtual assistant on Facebook Contact this virtual assistant on LinkedIn
Default Anyone know html javascript (hybrid type) coding
My son's best friend is taking computer courses and is having issues with this code: (it will not return the value) Any help would be greatly appreciated!

Thanks,
Rhonda


<html>
<head>
<title>PayrollApplication</title>
</head>
<body>
<script type="text/javascript">
function calcPay()
{
// Declarations:
var name;
var hoursWorked;
var rate;
var grossPay;
var HOURS_IN_WK = 40;
var OVERTIME_RATE = 1.5;

name = document.PayrollApplication.na me.value;
hoursWorked = document.PayrollApplication.hr sWorked.value;
rate = document.PayrollApplication.ra te.value;

if (hoursWorked > HOURS_IN_WK)
{
grossPay = rate * HOURS_IN_WK + ((hoursWorked - HOURS_IN_WK) * OVERTIME_RATE);
}
else
{
grossPay -= rate * hoursWorked;
}

window.alert("Your weekly gross pay is: ", grossPay);

} // end of function calcPay()
</script>

<form name="PayrollApplication">
Name: <input type="Text" name="name">
Hours worked: <input type="Text" name="hrsWorked">
Rate: <input type="Text" name="rate">
<input type="submit" value="Calculate pay" onClick="calcPay();">
</form>
</body>

</html>
__________________
Rhonda Holscher, Owner/CEO
Rhonda's Virtual Office - YOUR Virtual Assistant
Reply With Quote
    #2 (permalink)  
Old 04-23-2012
On My Wings's Avatar
On My Wings On My Wings is offline
Active Member
Company name: On My Wings International, LLC
 
Join Date: Oct 2008
Location: Centennial, Colorado
Posts: 805
Blog Entries: 2
Find this virtual assistant on Facebook Contact this virtual assistant on LinkedIn
Default Re: Anyone now html javascript (hybrid type) coding
Could it be this??? >>> Just at a quick glance without plugging it into an editor.
See in the last line - the 2nd gross pay. There is a hyphen before the = sign

if (hoursWorked > HOURS_IN_WK)
{
grossPay = rate * HOURS_IN_WK + ((hoursWorked - HOURS_IN_WK) * OVERTIME_RATE);
}
else
{
grossPay -= rate * hoursWorked;
}
__________________
Pam Blackman - On My Wings International
Integrated Virtual Business Management Solutions | Mentoring | Coaching
Reply With Quote
    #3 (permalink)  
Old 04-23-2012
RhondaHolscher's Avatar
RhondaHolscher RhondaHolscher is offline
Active Member
Company name: Rhonda's Virtual Office
 
Join Date: Feb 2010
Location: Cincinnati, OH, USA
Posts: 760
Blog Entries: 13
Send a message via Yahoo to RhondaHolscher
Follow this virtual assistant on Twitter Find this virtual assistant on Facebook Contact this virtual assistant on LinkedIn
Default Re: Anyone know html javascript (hybrid type) coding
I thought that as well, and I tried it in my editor and it still did not produce the answer. Thanks for taking a quick look though. It's greatly appreciated.
__________________
Rhonda Holscher, Owner/CEO
Rhonda's Virtual Office - YOUR Virtual Assistant
Reply With Quote
    #4 (permalink)  
Old 04-23-2012
Codehead Codehead is offline
Contributing Member
 
Join Date: Apr 2007
Location: Portland, Oregon
Posts: 177
Default Re: Anyone know html javascript (hybrid type) coding
Hi,

Replace this line:
Code:
window.alert("Your weekly gross pay is: ", grossPay);
With:
Code:
window.alert("Your weekly gross pay is: " + grossPay);
+ is for string concatenation in JavaScript...

Hope this helps.
Reply With Quote
    #5 (permalink)  
Old 04-24-2012
RhondaHolscher's Avatar
RhondaHolscher RhondaHolscher is offline
Active Member
Company name: Rhonda's Virtual Office
 
Join Date: Feb 2010
Location: Cincinnati, OH, USA
Posts: 760
Blog Entries: 13
Send a message via Yahoo to RhondaHolscher
Follow this virtual assistant on Twitter Find this virtual assistant on Facebook Contact this virtual assistant on LinkedIn
Default Re: Anyone know html javascript (hybrid type) coding
Thanks! He tried that and it returned a value of NaN.
__________________
Rhonda Holscher, Owner/CEO
Rhonda's Virtual Office - YOUR Virtual Assistant
Reply With Quote
    #6 (permalink)  
Old 04-24-2012
Codehead Codehead is offline
Contributing Member
 
Join Date: Apr 2007
Location: Portland, Oregon
Posts: 177
Default Re: Anyone know html javascript (hybrid type) coding
This code works for me:

Code:
<html>
<head>
<title>PayrollApplication</title>
</head>
<body>
<script type="text/javascript">
function calcPay()
{
// Declarations:
var name;
var hoursWorked;
var rate;
var grossPay;
var HOURS_IN_WK = 40;
var OVERTIME_RATE = 1.5;

name = document.PayrollApplication.name.value;
hoursWorked = document.PayrollApplication.hrsWorked.value;
rate = document.PayrollApplication.rate.value;

if (hoursWorked > HOURS_IN_WK)
{
grossPay = rate * HOURS_IN_WK + ((hoursWorked - HOURS_IN_WK) * OVERTIME_RATE);
}
else
{
grossPay -= rate * hoursWorked;
}

window.alert("Your weekly gross pay is: " + grossPay);

} // end of function calcPay()
</script>

<form name="PayrollApplication">
Name: <input type="Text" name="name">
Hours worked: <input type="Text" name="hrsWorked">
Rate: <input type="Text" name="rate">
<input type="submit" value="Calculate pay" onClick="calcPay();">
</form>
</body>

</html>
Notice the difference between these lines:

Code:
name = document.PayrollApplication.name.value;
hoursWorked = document.PayrollApplication.hrsWorked.value;
rate = document.PayrollApplication.rate.value;
From the ones you posted.

Good luck
Reply With Quote
Reply

« Previous Thread | Next Thread »
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Forum Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript or something else Williams General Website Design and Development 2 07-30-2011 01:23 PM
BOOK REVIEW - JavaScript Demystified: A Self Teaching Guide dognose Website Coding 2 04-07-2010 09:59 PM
[Problem] Using one HTML or Javascript template file for your website navigation menu forwardvision Website Coding 4 09-29-2009 05:53 PM
html coding Bevalee Website Coding 1 04-23-2009 10:06 PM
Form Actions HTML Coding White Rose Website Coding 7 04-15-2008 09:26 PM


All times are GMT -4. The time now is 07:59 AM.

Virtual Assistant Forums Advertising
Featured VA websites:

TyChi Management Group

Long Distance Assistants

247 Virtual Assistant
Get featured!
Bankruptcy Virtual Assistant Training
Virtual Assistant Forums Advertising
Virtual Assistant Contracts
Virtual Assistant Forums Advertising
Work from Home | Become A Virtual Assistant

© Virtual Assistant Forums 2013
All content and images are protected under copyright law and may not be reproduced in any way without express written consent.