checkbox problems?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rabel

    #1

    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

  • Rabel

    #2
    Re: checkbox problems?

    No ideas?

    Comment

    • Duncan Booth

      #3
      Re: checkbox problems?

      Rabel wrote:
      [color=blue]
      > No ideas?
      >[/color]
      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.
      [color=blue]
      > 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[/color]

      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

      Comment

      • Rabel

        #4
        Re: checkbox problems?

        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

        Comment

        • Dr John Stockton

          #5
          Re: checkbox problems?

          JRS: In article <1116528773.238 123.173150@f14g 2000cwb.googleg roups.com>
          , dated Thu, 19 May 2005 11:52:53, seen in news:comp.lang. javascript,
          Rabel <Randy@Creative ness.com> posted :
          [color=blue]
          >if(isNaN(frm.p hone.value) || frm.phone.value .length <10)
          >{
          >alert("Pleas e enter a valid telephone number");
          >return false;
          >}[/color]

          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
          <lnwtuhfy7d.fsf @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.

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: checkbox problems?

            Rabel wrote:
            [color=blue]
            > You are an idiot duncan,[/color]

            I don't like several people here either, however with me
            there is enough courtesy left to refrain from such.
            [color=blue]
            > I did ask a question, and I was only asking for help[/color]

            Does not matter anymore. Go away, please.
            [color=blue]
            > [...]
            > For everyone else out there who may have the same problem this is what
            > I used to solve it[/color]

            It is not Valid (X)HTML, it is highly inefficient and it is flawed.


            PointedEars

            Comment

            • Rabel

              #7
              Re: checkbox problems?

              oh well it works for what i need it to do

              Comment

              Working...