Unwanted Pointer Variable

Discussion in 'JavaScript' started by somody, Jun 24, 2007.

  1. #1
    I was making a small JavaScript program and I found that when I make a local variable from the value of an HTML input field,...
    var abcd = document.myform.abcd.value;
    Code (markup):
    ...it makes a pointer back to the field so that when I change the local variable...
    abcd = 1;
    Code (markup):
    ...the field located at document.myform.abcd.value changes its value to 1 as well. I know enough about programming theory to know that I created a pointer back to the field value "object" (if this were object-oriented). But how to I just copy the value of the field into the local variable and leave it at that so that no modifications to the local variable will change the input field itself?
     
    somody, Jun 24, 2007 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    I don't believe it. Could you produce a runnable example?
     
    Logic Ali, Jun 24, 2007 IP
  3. somody

    somody Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, you were right not to believe it. :)
    I forgot to refresh after I resaved the source. Wow.
     
    somody, Jun 24, 2007 IP
  4. samusexu

    samusexu Well-Known Member

    Messages:
    138
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Hehe, I wish there were pointers in javascript, it would have been JS++ :)
     
    samusexu, Jun 26, 2007 IP