Can you help me to write very simple script? First, check this website: http://www.private-card.com/loading.html I want to create a form like this site. I want ‘Amount to be load’ must be number. When they enter amount, no 2% fee like this site. But if they enter amount from: 1-10: Amount after fee * 4 11-30: *3.5 31-60: *2.5 >= 61: *2 And it’ll show ‘Amount after fee’ instant, user must enter number, not text or anthing else. System will show error… That’s all. Thanks
Try this... Demo: http://home.earthlink.net/~duhomax/amount_after_fee.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Amount After Fee Test</title> <style type="text/css"> form { margin: 0px; } body { font: 10pt verdana, arial, sans-serif; } div.row { margin-bottom: 3px; width: 217px; text-align: right; } div#calc_button_row { margin-top: 5px; margin-bottom: 5px; } input#clear_button { margin-right: 3px; } </style> <script type="text/javascript"> <!-- var auto_calculate = false; // if set to true, calculation will happen automatically window.onload = put_focus; function put_focus() { if (document.getElementById) { document.getElementById('amount_to_load_textbox').focus(); } } function handle_key_press() { var keycode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; switch (keycode) { case 13: event.returnValue = false; calculate(); break; case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: break; default: event.returnValue = false; } return true; } function handle_key_up() { if (auto_calculate) { calculate(); } } function calculate() { if (document.getElementById) { var t1 = document.getElementById('amount_to_load_textbox'); var t2 = document.getElementById('amount_after_fee_textbox'); var t1_value = parseInt(t1.value); if (t1_value == 0) { alert('Please enter an amount greater than zero.'); return false; } if (t1.value == '') { t2.value = ''; return false; } if (t1_value > 0 && t1_value <= 10) { t2.value = t1_value * 4; } else if (t1_value >= 11 && t1_value <= 30) { t2.value = t1_value * 3.5; } else if (t1_value >= 31 && t1_value <= 60) { t2.value = t1_value * 2.5; } else if (t1_value >= 61) { t2.value = t1_value * 2; } } } function clear_boxes() { if (document.getElementById) { document.getElementById('amount_to_load_textbox').value = ''; document.getElementById('amount_after_fee_textbox').value = ''; document.getElementById('amount_to_load_textbox').focus(); } } //--> </script> </head> <body> <form action="" onsubmit="return false"> <div class="row"> <label for="amount_to_load_textbox" id="amount_to_load_label">Amount to load:</label> <input type="text" size="10" id="amount_to_load_textbox" onkeypress="handle_key_press()" onkeyup="handle_key_up()" /> </div> <div class="row"> <label for="amount_after_fee_textbox">Amount after fee:</label> <input type="text" size="10" readonly="readonly" id="amount_after_fee_textbox" /><br /> </div> <div class="row"> <input type="checkbox" id="auto_calculate_checkbox" onclick="auto_calculate=this.checked" /> <label for="auto_calculate_checkbox" id="auto_calculate_label">Auto Calculate</label> </div> <div class="row" id="calc_button_row"> <input type="button" id="clear_button" value="Clear" onclick="clear_boxes()" /> <input type="submit" id="calculate_button" value="Calculate" onclick="calculate()" /> </div> </form> </body> </html> Code (markup):
Hello, I want to ask some questions about javascript… I have a form with: - 2 products checkbox - 1 type checkbox - 2~3 radio button - 1 total prices form I want: - When user check ‘products checkbox’, it’ll add prices (I can set, ex: $5, $10) of these products to ‘total prices’ - They can select ‘type checkbox’ if they check ‘product 1 checkbox above’ and add $15 to ‘total prices’. If not, they can’t use this checkbox, it’s disable. - Then they must select 1 in 2~3 radio button. (ex: paypal, egold, moneybookers…) - ‘total prices’ will show all $ by checkbox User submit info, all data will send to me. And user will be goto payment page instant, they can select pay button (value radio button) with ‘total prices’ value. They will be redirect to payment page and pay. Ex: User select 2 products (total is $5+$10 = $15) They can select ‘type checkbox’ (total is $15+$15=$30) They select paypal radio button They click submit, email send to me and they goto page with paypal button, they can click it and goto pay $30 ‘total prices’. I use email script at: http://regretless.com/scripts/ex/dodosmail2_0/longform.php I want check form javascript for my custom form. Thanks so much.