Need help with OnClick

Discussion in 'JavaScript' started by x0x, Jan 11, 2010.

  1. #1
    onclick="trn.value='<?=$var?>'"


    it fills a textbox with the $var value, which is a number. The box should only hold a max of 99,999, therefore if $var is bigger than 99,999,
    10,000,000 for example it would only put 99999 in the box. Can that be done somehow?
     
    x0x, Jan 11, 2010 IP
  2. mycollection

    mycollection Peon

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    make one js function for validation .. and call it on key press or value change :)
     
    mycollection, Jan 11, 2010 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I'm a noob when it comes to js. But I can do it in PHP and assign the value to a new variable - not a bad idea at all. :D
     
    x0x, Jan 11, 2010 IP
  4. Gungz

    Gungz Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So, u still need a help for the JS or not?
     
    Gungz, Jan 11, 2010 IP
  5. w3goodies

    w3goodies Member

    Messages:
    94
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #5
    Does it helps:
    
    <input type="text" id="number"><br>
    <input type="text" id="number2"><br>
    <a href="#" onClick="if(document.getElementById('number').value > 999999){alert('BIG NUMBER!');}else{document.getElementById('number2').value=document.getElementById('number').value;}">CLICK ME</a>
    Code (markup):
     
    w3goodies, Jan 12, 2010 IP
  6. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    I think you got the wrong idea, but it is still helpful.

    $var = 10000;

    I do click on a button that has the onclick property and it inserts $var to a textbox


    <input type="text" name="trn"/>

    <input value="*" onclick="trn.value='<?=$var?>'" type="button">

    But what I want to do is when $var exceeds 99999, it should only insert 99999 to the textbox, not a bigger number.


    So, if $var = 213453642145424;

    onclick will just insert 99999 to the textbox, and if it's smaller it enters the actual number.
     
    x0x, Jan 12, 2010 IP
  7. w3goodies

    w3goodies Member

    Messages:
    94
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #7
    Try this:
    
    <input type="text" id="number"><br>
    <input type="text" id="number2"><br>
    <a href="#" onClick="if(document.getElementById('number').value.length > 5){document.getElementById('number2').value = document.getElementById('number').value.substring(0, 5);}else{document.getElementById('number2').value=document.getElementById('number').value;}">CLICK ME</a>
    Code (markup):
     
    Last edited: Jan 12, 2010
    w3goodies, Jan 12, 2010 IP