Buying $5 for quick javascript help

Discussion in 'Programming' started by selltrib, Apr 16, 2010.

  1. #1
    I'm trying to setup a few dynamic hyperlinks to update a value on a form. There can be multiple input boxs so i'm trying this

    
    <form method="post" name="video">
    <input type="text" name="data_db_database_id id="data_db_database_id" value="db_data_value" maxlength="4" size="4"></td>
    </form>
    
    PHP:
    This loads from a database in which the table has 2 rows so on the screen i have 2 input boxes with names of "data01", "data02" and id's of "data01","data02" the form details are outside of the loop


    I have 1 java script function called 'setdefaultvalue' and i have a dynamic hyperlink loaded next to each box to set a default value if i need to. the calling code is

    
    <a href=# onclick="javascript:return setdefaultvalue(7551)"ENCTYPE="multipart/form-data">Set default</a>				  
    
    PHP:
    Which calls the below value and set the default value for the first field and works perfectly.
    
    function setdefaultvalue(value){
    var MyElement = document.video.data01;
    MyElement.value = value;
    }
    
    PHP:
    However if I try and make the function take a input box via calling it. I can't get it to work.


    
    function setdefaultvalue(value,whatele){
    var MyElement = document.video.getElementById(whatele);
    MyElement.value = value;
    }
    
    PHP:
    And the hyper link code is below

    
    <a href=# onclick="javascript:return setdefaultvalue(7551,'data01')"ENCTYPE="multipart/form-data">Set default</a>				  
    
    PHP:
    Anyone able to help me out on this one. $10 via paypal for the first person to give the correct solution
     
    Last edited: Apr 16, 2010
    selltrib, Apr 16, 2010 IP
  2. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    As Seller:
    100% - 0
    As Buyer:
    25.0% - 1
    #2
    replace this

    var MyElement = document.video.getElementById(whatele);

    with

    var MyElement = document.getElementById(whatele);
     
    kishore415, Apr 16, 2010 IP
  3. selltrib

    selltrib Peon

    Messages:
    1,442
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Hi I tried that before but I get a MyElement is null javascript error
     
    selltrib, Apr 16, 2010 IP
  4. selltrib

    selltrib Peon

    Messages:
    1,442
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    The part I forgot to add about this was it's using the smarty php overlay but shouldn't make too much of a difference to the java script as long as it's properly setup
     
    selltrib, Apr 16, 2010 IP
  5. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    As Seller:
    100% - 0
    As Buyer:
    25.0% - 1
    #5
    Fixed by me...thanks
     
    kishore415, Apr 16, 2010 IP