473,383 Members | 1,874 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,383 software developers and data experts.

checkbox problems?

I have a shopping cart that I am having a few problems with. I am
mostly a flash developer with basic if not little javascript knowledge,
I need for my checkout to have a checkbox that if clicked on will
populate my shipping addresses with my billing addresses, I have this
somewhat working with a code I got off of here thats like this

<script>
function copy(checked, source, target) {
if (checked) {
target.value = source.value
} else {
target.value = '';
}
}
</script>
//then like this in the form
<input type=checkbox onClick="copy(this.checked, this.form.bname,
this.form.sname)">

but the problem with that is that I have to put a checkbox with its own
code on each part of the form. I would like to have one that would
then populate the whole form. The other question I have is I need to
have a validate script from the form, the fields are

Name-text
address-text
city-text
state-select
zip-text
country-selected US
Phone-text
email-text

credit card number-text- just need it to check if its numbers and over
12

Any help is greatly appreciated, thanks in advance

Jul 23 '05 #1
6 1383
No ideas?

Jul 23 '05 #2
Rabel wrote:
No ideas?
I think the problem may be that you didn't actually ask a question. This
isn't a place to get people to write your code for you from scratch, it
is a place to ask questions when you get stuck. Try showing us what you
have tried so far, say what you expected it to do and what it actually
does and then maybe someone will suggest where you are going wrong.
I would like to have one that would then populate the whole form.
The other question I have is I need to have a validate script from
the form


On the face of it you stated that you wanted to do something pretty
obvious so my response would be 'so do it'.

See also http://www.catb.org/~esr/faqs/smart-questions.html
Jul 23 '05 #3
You are an idiot duncan, I did ask a question, and I was only asking
for help I believe I said
'Any HELP is greatly appreciated, thanks in advance'
but you decided that I knew what I was doing and suggested 'so do it'
well thanks man you were a lot of help. Who sits there and complains
about someones question anyway, get a life.

For everyone else out there who may have the same problem this is what
I used to solve it

<script>
function doit(obj,name,address,cityv,statev,zipcode)
{
if(obj.checked)
{
document.frm.elements[name].value = document.frm.bname.value
document.frm.elements[address].value = document.frm.baddr1.value
document.frm.elements[cityv].value = document.frm.bcity.value
document.frm.elements[statev].value = document.frm.bstate.value
document.frm.elements[zipcode].value = document.frm.bzip.value
}
else
{
document.frm.elements[name].value = ""
document.frm.elements[address].value = ""
document.frm.elements[cityv].value = ""
document.frm.elements[statev].value = ""
document.frm.elements[zipcode].value = ""
}
}
function validate()
{
var frm = document.frm

if(frm.bname.value == "" )
{
alert("Please enter valid billing first and last name");
return false;
}
if(frm.sname.value == "" )
{
alert("Please enter valid shipping first and last name");
return false;
}
if(frm.baddr1.value == "" )
{
alert("Please enter valid billing address");
return false;
}
if(frm.saddr1.value == "" )
{
alert("Please enter valid shipping address");
return false;
}
if(frm.bcity.value == "")
{
alert("Please enter valid billing city");
return false;
}
if(frm.scity.value == "")
{
alert("Please enter valid shipping city");
return false;
}
if(isNaN(frm.bzip.value) || (frm.bzip.value.length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.szip.value) || (frm.szip.value.length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.cardnumber.value) || frm.cardnumber.value.length <13)
{
alert("Please enter valid creditcard number");
return false;
}
if(isNaN(frm.phone.value) || frm.phone.value.length <10)
{
alert("Please enter a valid telephone number");
return false;
}
if(trimit(frm.email.value) != "")
{
return emailTest(frm.email)

}
}
function emailTest(obj){
reg=
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (!reg.test(obj.value) ){
alert('Invalid email address')
obj.focus()
return false;
}
}

function trimit(strInput)
{
return strInput.replace(/^\s*/,"").replace(/\s*$/,"");

}
</script>
//in the form tag
onsubmit="return validate()
//then on the checkbox
<input type = "checkbox" name = "chk" onclick =
"doit(this,'sname','saddr1','scity','sstate','szip ');">

Hope that helps

Jul 23 '05 #4
JRS: In article <11**********************@f14g2000cwb.googlegroups .com>
, dated Thu, 19 May 2005 11:52:53, seen in news:comp.lang.javascript,
Rabel <Ra***@Creativeness.com> posted :
if(isNaN(frm.phone.value) || frm.phone.value.length <10)
{
alert("Please enter a valid telephone number");
return false;
}


Please use proper quoting and attributions on Usenet :-

For proper quoting when using Google for News :-
Keith Thompson wrote in comp.lang.c, message ID
<ln************@nuthaus.mib.org> :-
If you want to post a followup via groups.google.com, don't use
the "Reply" link at the bottom of the article. Click on "show
options" at the top of the article, then click on the "Reply" at
the bottom of the article headers.
That's rather crude validation - it will accept 0xFeedBeef and
0xDeadFade, for example. Similarly for other answers.

Better to test with a RegExp such as /^\d{10,}$/.test(frm.phone.value)
which calls explicitly for 10 or more decimal digits. OTOH, it would be
sensible to permit customary punctuation.

See <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

Replacing everything like

if(frm.bcity.value == "")
{
alert("Please enter valid billing city");
return false;

with like

if (Bad(frm.bcity, "Please enter valid billing city")
return false;

and a function like

function Bad(C, S) { var B = C.value == ""
if (B) alert(S)
return B }

would make your code more readable, more maintainable, and probably
shorter.
The function in your first article,

function copy(checked, source, target) {
if (checked) {
target.value = source.value
} else {
target.value = '';
}
}

could be written as

function copy(checked, source, target) {
target.value = checked ? source.value : '' }

Code presented for others to read should be indented to show intended
structure.

Your code serves well as an example not to be followed.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
Rabel wrote:
You are an idiot duncan,
I don't like several people here either, however with me
there is enough courtesy left to refrain from such.
I did ask a question, and I was only asking for help
Does not matter anymore. Go away, please.
[...]
For everyone else out there who may have the same problem this is what
I used to solve it


It is not Valid (X)HTML, it is highly inefficient and it is flawed.
PointedEars
Jul 23 '05 #6
oh well it works for what i need it to do

Jul 23 '05 #7

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

Similar topics

7
by: Old Lady | last post by:
Hi all, I have a problem when I try to send an array using a form when the type="checkbox". This is my form input row: <INPUT type="Checkbox" name="flg" value="y" <? if($row == 'y') echo...
4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
2
by: Tomas Vera | last post by:
Hello All, I'm having problems creating a page with dynamic checkboxes in a WebApp. In my app, I need to query a database, then (based on results) add checkboxes to my form and set their...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
1
by: Paul | last post by:
HI I have a asp page which dynamically creates a table with 28 rows, 3 columns. Column 1 contains a label, column 2 contains a graphic, column 3 needs to contain a checkbox. I have no problems...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
6
by: tshad | last post by:
I am trying to disable and enable a checkbox from javascript. The problem is that if the checkbox starts out as: <input id="Override" type="checkbox" name="Override"/> I can change it back...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
11
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, I have a large recordset to be displayed on a ASP 3.0 page. I am using recordset paging for this. For the next and previous link i am passing href as <a href=<Page URl>?page=<%=...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.