1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

value of input tag

Discussion in 'JavaScript' started by startdream, Jan 12, 2012.

  1. #1
    I have a data object:
    var o_Data =new Object();
    o_Data.title ='<script>alert("1");</script>';
    o_Data.value ='3';
    When i used JSON.stringify(o_Data), then put in to value of input tag
    <input value=\'' + JSON.stringify(o_Data) + '\' type="radio" name="data" class="hide"/>
    I don't understand why
    Actual Result:
    Expected Result:

     
    startdream, Jan 12, 2012 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    try to add escape function

    
    <input value=\'' + escape(JSON.stringify(o_Data)) + '\' type="radio" name="data" class="hide"/>
    
    Code (markup):
     
    JohnnySchultz, Jan 17, 2012 IP
  3. startdream

    startdream Member

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    28
    #3
    i trying but not right
     
    startdream, Jan 18, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    have you tried creating an element via DOM?

    
    
    var o_Data =new Object();
    o_Data.title ='&lt;script&gt;alert("1");&lt;/script&gt;';
    o_Data.value ='3';
    
    var input =  document.createElement('input');
         input.type = "radio";
         input.name = "data";
         input.className = "hide";
         input.value = JSON.stringify(o_Data);
    
    document.getElementById("the_container").appendChild(input); // the_container is the ID of the element where you want the radio button to be placed inside
    
    
    Code (markup):
     
    JohnnySchultz, Jan 19, 2012 IP