Pleaseeeeee help

Discussion in 'JavaScript' started by PraveenAnekalmat, Apr 26, 2007.

  1. #1
    Hi everyone,

    Please observe the below code

    fun(){
    for(i = 1; i < = j; i++){
    select = document.forms['MessageNew'].userId.options.value;
    selection = '<a href="javascript:assignValue(select);"> + select + </a>';
    }
    }

    I am calling function fun(), for loop executes and number of links will appear depending on the value of j.What i am trying to do is, i need to pass 'select' value for each links when i click the link but only final select value i.e for i=j, is going.so if i click any link only last select value(i=j) will go because looping has completed.
    i need 'select' values for all the valuse of i.
    Do i need to give id to anchor ? how to approach this?
     
    PraveenAnekalmat, Apr 26, 2007 IP
  2. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am confused by your post, please try to re-explain... but anyway
    fun(){
    should be
    function fun(){
     
    bobby9101, Apr 27, 2007 IP
  3. PraveenAnekalmat

    PraveenAnekalmat Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Bobby..thanks a lot for your response...

    Please observe the below code

    function fun(){
    for(i = 1; i < = j; i++){
    select = document.forms['MessageNew'].userId.options.value;
    selection = '<a href="javascript:assignValue(select);"> + select + </a>';
    }
    }

    Assume j = 10, looping will happen for 10 times and 10 links will appear.
    Let us assume value of 'select' is 'ABCD' when i = 1 and at i = 10, value of select will be 'XYZ' . Observe that in href we are calling one javascript function assignValue(select) and passing select in that. This javascript will be called when i click the link, even i click link number 1, XYZ will be passed to the assignValue() since looping is completed. But i need ABCD to be passed when i click link 1 and the respective values should be passed for link2,link3...,link10.
    I hope you got my prob..Please help me how can i approach the solution.
     
    PraveenAnekalmat, May 4, 2007 IP
  4. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi I am still not really sure what you want, but maybe:

    function fun(){
    var j = 10;
    var select;
    for(i=1;i<=j; i++){
    select = document.forms['MessageNew'].userId.options.value;
    selection = '<a href=" + select + " onclick="assignValue(select)"> + select + </a>';
    }
    }
     
    bobby9101, May 4, 2007 IP
  5. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #5
    You should fix at least this:
    - Use '<=' instead of '< =' (no spaces inside)
    - You select variable must be outside your string.
    - The solution is different depending of the type of parameter (numeric or string) of assignValue function. Take this html as example:

    
    <html>
    <head />
    
    <body onload="fun()">
    
    <script type="text/javascript">
    
    var value = [ "", "AB", "CDE", "E" ];
    var selectionNumber = [ 0, 0, 0, 0 ];
    var selectionString = [ "", "", "", "" ];
    function fun()
    {
      for(i = 1; i <= value.length; i++)
      {
        select = value[i];
        selectionNumber[i] = '<a href="javascript:assignValue(' + select + ');">' + select + '</a>';
        selectionString[i] = '<a href="javascript:assignValue(\'' + select + '\');">' + select + '</a>';
        alert( "sn='" + selectionNumber[i] + "'\nss='" + selectionString[i] + "'" );
      }
    }
    
    </script>
    
    </body>
    </html>
    
    Code (markup):
     
    ajsa52, May 4, 2007 IP
  6. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What is the code for the assignValue() function
     
    bobby9101, May 4, 2007 IP