Javascript Copy Text Boxes..I'm being stupid!

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

    Javascript Copy Text Boxes..I'm being stupid!

    I know this is probably a real simple one, but I'm obviously missing
    something..

    I'm building a function that I'll use throughout a website in the situation
    that I have two text boxes - the two text boxes will generally contain the
    same data. After the user completes the value of the first textbox, I want
    to onChange the value of the first textbox into the second textbox UNLESS
    the second textbox already has a value.

    Here's what I've done so far...

    IN THE HEAD
    function CopyTextBoxes(T extBox1,TextBox 2) {
    if(TextBox2.val ue = '') {
    TextBox2.value = TextBox1.value}
    }

    IN THE BODY WITHIN THE FORM
    <input name="MailFrom" type="text" id="MailFrom" size="60" maxlength="100"
    onChange="CopyT extBoxes('MailR eplyTo','MailFr om')">
    <input name="MailReply To" type="text" id="MailFrom" size="60"
    maxlength="100" >

    I hate javascript, and will really appreciate your help!

    Thanks!


  • @sh

    #2
    Re: Javascript Copy Text Boxes..I'm being stupid!

    Hi Lee,

    Thanks for your reply. I've tried as you suggested but instead of copying
    the value into the second text box its simply blanking it, whether populated
    with data or not.

    Where you have added 'this.form', must I change the 'form' part to the name
    of my form? Is there a way I can specify the form name in as a parameter?

    Any ideas?

    Cheers, Ash


    Comment

    • @sh

      #3
      Re: Javascript Copy Text Boxes..I'm being stupid!

      Thanks very much Lee! So infact I wasn't far off other than mixing my
      source/destination fields, and missing an operator!

      All is working now. Thanks all that replied for your feedback, I do
      appreciate the detailed responses, and alternative code although it is nice
      to get a solution (as with that provided by Lee) that incorporates your
      original work, i.e. in this case I have now learn't how to avoid making the
      same mistake again (those damn equal's signs), as opposed to simply taking
      someone elses version of script that will ultimately do the same thing.

      Thanks!


      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:dnnjh902m4 4@drn.newsguy.c om...[color=blue]
      > @sh said:[color=green]
      >>
      >>Hi Lee,
      >>
      >>Thanks for your reply. I've tried as you suggested but instead of copying
      >>the value into the second text box its simply blanking it, whether
      >>populated
      >>with data or not.
      >>
      >>Where you have added 'this.form', must I change the 'form' part to the
      >>name
      >>of my form? Is there a way I can specify the form name in as a parameter?[/color]
      >
      > No, every form element has an attribute named "form" which is a reference
      > to the form which contains it, so "this.form" is your form.
      >
      > I had overlooked another error in your code:
      >
      > if(TextBox2.val ue = '') {
      >
      > That should be:
      >
      > if(TextBox2.val ue == '') {
      >
      > the "=" symbol is an assignment operator, which is why the field
      > was being blanked. The equality test operator is "==".
      >[/color]


      Comment

      Working...