access form input values

Discussion in 'JavaScript' started by promotingspace.net, Oct 1, 2010.

  1. #1
    Hi
    I was trying to access form input values but the field names are dynamic and I couldn't make it work
    Any help would be extremely appreciated
    This is the function that is not working
    
    function SaveRating(resourceId,order_id)
    {
      var r1="response"+resourceId;
      var s1="schedule"+resourceId;
      var a1="accurate"+resourceId;
      
      
    	var r=document.form1.r1.value;
    	var s=document.form1.s1.value;
    	var a=document.form1.a1.value;
    	
    	var url="orderDetail.php?resourceId="+resourceId+"&r="+r+"&s="+s+"&a="+a+"&order_id="+order_id+"&rate=1";
    	window.location.href=url; 
    }
    Code (markup):

     
    promotingspace.net, Oct 1, 2010 IP
  2. wab

    wab Member

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    if r1 is your input id, you should try this instead
    
    var r1="response"+resourceId;
    var r=document.getElementById(r1).value;
    
    Code (markup):
     
    wab, Oct 1, 2010 IP
  3. GFX_Lover

    GFX_Lover Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This will do ;)

    javascript:arr = [];x = 0;
    for(i in (d = document.forms[0].elements)){
    arr[x] = d.value;x+=1
    }
    alert(arr.join("\n"))
     
    GFX_Lover, Oct 3, 2010 IP