SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Newbie problem

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Newbie problem

    hi all
    i'm making a page for my website, a simple color conversor and then show the hex color, but i have some problems in the page.
    i have the page working, but isn't simplificate, and i want to simplificate,I want only 2(one for the button +, and one for the button -) functions instead of 12 ( 6 for the button +, and 6 for the button -)

    when i click + or -, change only that number in that position.

    the page is in http://lfvo.no.sapo.pt/teste.html

    Best,
    Lfvo

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,498
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    radio buttons?

    Hi lfvo, welcome to the forums,
    Maybe have 2 rows of radio buttons, (one row for each) eg.
    ooo - and ooo +
    or maybe next to each box like
    o[] o[] o[]``````o[] o[] o[]
    `````````[-] [+]``````
    Then which ever radio is checked is the one the button changes

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi
    interesting ideia thanks, maby i adopt that ideia in a future version 2, but I am trying to discover what i'm doing wrong, so that in future I don't do the same mistake again

    one of the thing i doing wrong is this numhexa=a[num];, i dont know how i order to change only that position, the others error i dont know :S

    Best,
    Lfvo

  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi
    Excuse to be upsetting again, but I had just resolved one of the problems. but now one of the problems is not modifying the number in top in the Hexa text box.
    here's the website: http://lfvo.no.sapo.pt/teste.html
    the code in question is:
    var n1=convHexDec(eval(num).value);
    if (n1>0)
    n1=n1-1;
    else
    n1=15;
    eval(num).value=convDecHex(n1);
    x=parseInt(num);
    a[x]=eval(num).value;
    numhexa=a[0]+a[1]+a[2]+a[3]+a[4]+a[5];
    n2.value="#" + numhexa;
    hexacor=numhexa;
    n1.value=convHexDec(numhexa);
    }
    sry my english

    lfvo

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,498
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    bugs

    I'm getting a "problem loading page" error for the link.
    From what I remember from the last time I looked at it, the error console was giving a lot of errors for the "DOM hooks". For example, instead of accessing an element "directly" like elem.id.value, it wanted something like
    HTML Code:
    var target_elem = document.getElementById('id_here');
    which can then be accessed like
    HTML Code:
    var elem_val = target_elem.value;
    target_elem.value = elem_val + 1;
    etc.
    I don't know if "eval(num).value" indicates that you're using numbers for id names, but if so, they won't work. Id names can not begin with (or be only) numbers.
    As for changing the "look and feel" of your script, I couldn't see any way to "fix it up" short of rewriting it, so I hoped maybe somene else would chime in. But hopefully you've managed to find something suitable for your design goal, and now only have "syntax" problems remaining.

  6. #6
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i was using the numbers, because i was using the numbers to indicate the position of the string where it should save the value. for example, i give the name txt0, txt1, txt2, txt3, txt4, txt5, for the texts boxs, what code i can do, when i click for example in the + or - in the txt4, and it sends the respective value for the position a[4] of the string.

    a is the string name.
    i hope isn't very confused
    here's the page is without simplifications http://lfvo.no.sapo.pt/color_teste.html

    thanks for the help Mittineague

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,498
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    id names

    txt1, txt2, etc should be fiine, But if instead of going to
    HTML Code:
    <form id="f1"> ... <input type="text" id="n2" size="7" maxlength="7" value="#FFFFFF"/>
    by
    HTML Code:
    f1.n2.value="#" + numhexa;
    it should work better the DOM way. eg.
    HTML Code:
    var cor_n2 = document.getElementById('n2');
    cor_n2.value = "#" + numhexa;

  8. #8
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks i will put that.

    but for the simplificate way, because i have 12 functions for the buttons :S how can i do this?
    for example, i give the name txt0, txt1, txt2, txt3, txt4, txt5, for the texts boxs, what code i can do, when i click for example in the + or - in the txt4, and it sends the respective value for the position a[4] of the string.

    what i have right now in the simplificate way is this http://lfvo.no.sapo.pt/color.html and the big problem is to tell the string the certain place to store the value.

    i finaly solved the problem
    thanks for the help and sugestions
    Last edited by lfvo; Jun 7, 2007 at 08:11.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •