473,698 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(t his.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 1405
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,a ddress,cityv,st atev,zipcode)
{
if(obj.checked)
{
document.frm.el ements[name].value = document.frm.bn ame.value
document.frm.el ements[address].value = document.frm.ba ddr1.value
document.frm.el ements[cityv].value = document.frm.bc ity.value
document.frm.el ements[statev].value = document.frm.bs tate.value
document.frm.el ements[zipcode].value = document.frm.bz ip.value
}
else
{
document.frm.el ements[name].value = ""
document.frm.el ements[address].value = ""
document.frm.el ements[cityv].value = ""
document.frm.el ements[statev].value = ""
document.frm.el ements[zipcode].value = ""
}
}
function validate()
{
var frm = document.frm

if(frm.bname.va lue == "" )
{
alert("Please enter valid billing first and last name");
return false;
}
if(frm.sname.va lue == "" )
{
alert("Please enter valid shipping first and last name");
return false;
}
if(frm.baddr1.v alue == "" )
{
alert("Please enter valid billing address");
return false;
}
if(frm.saddr1.v alue == "" )
{
alert("Please enter valid shipping address");
return false;
}
if(frm.bcity.va lue == "")
{
alert("Please enter valid billing city");
return false;
}
if(frm.scity.va lue == "")
{
alert("Please enter valid shipping city");
return false;
}
if(isNaN(frm.bz ip.value) || (frm.bzip.value .length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.sz ip.value) || (frm.szip.value .length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.ca rdnumber.value) || frm.cardnumber. value.length <13)
{
alert("Please enter valid creditcard number");
return false;
}
if(isNaN(frm.ph one.value) || frm.phone.value .length <10)
{
alert("Please enter a valid telephone number");
return false;
}
if(trimit(frm.e mail.value) != "")
{
return emailTest(frm.e mail)

}
}
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.replac e(/^\s*/,"").replace (/\s*$/,"");

}
</script>
//in the form tag
onsubmit="retur n validate()
//then on the checkbox
<input type = "checkbox" name = "chk" onclick =
"doit(this,'sna me','saddr1','s city','sstate', 'szip');">

Hope that helps

Jul 23 '05 #4
JRS: In article <11************ **********@f14g 2000cwb.googleg roups.com>
, dated Thu, 19 May 2005 11:52:53, seen in news:comp.lang. javascript,
Rabel <Ra***@Creative ness.com> posted :
if(isNaN(frm.p hone.value) || frm.phone.value .length <10)
{
alert("Pleas e 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.or g> :-
If you want to post a followup via groups.google.c om, 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.demo n.co.uk/js-valid.htm>.

Replacing everything like

if(frm.bcity.va lue == "")
{
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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
3143
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 'CHECKED'; ?>> Since this is an update form, I set the status of the flg according to the field "flag" stored in a MySQL database. The user may check or
4
6167
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 values from a html form that consists of about 10 checkbox and a textbox where user have to key in a value to perform a search. From python tutors, I learned that I have to use the following method:
4
4629
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 type="checkbox" name="chk_Complete" value="<%Response.Write l_IsChecked%>"<%if cbool(l_IsChecked) then Response.Write " checked"%>> The code to captures the checkbox value in the asp page that builds the sql string is follows
2
2335
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 "Checked" state. Since the controls are dynamically created, I'm using the OnInit event to create the checkboxes and set the "Checked" state from the DB. Next, I want to capture the postback event (AutoPostBack=true) and update my database based on...
2
3136
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
1
2152
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 with column 1 & 2, but column 3 gives me this error :- Control 'CHECKBOX1' of type 'CheckBox' must be placed inside a form tag with runat=server. Any ideas?
34
3810
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 function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
6
23838
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 and forth with no problems. using disabled = true or disabled = false If I start out as:
0
4097
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 with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
11
4311
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=<%= iPageCurrent - 1 %for Previous. Now when i display the contents i also add a checkbox (for deletion) to each of the records. Now user should be able to select one or more checkboxes across pages and then should be allow to delete all selections together....
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.