www.webdeveloper.com
Results 1 to 3 of 3

Thread: unsuccess to assign array values to textbox

  1. #1
    Join Date
    Jul 2013
    Posts
    6

    Question unsuccess to assign array values to textbox

    I am writing javascript that splits an array based on delimiter(,) and puts that value to text box. Each array contains exact five comma separated values. I tried the below code and getting error

    "Error: Object doesn't support this property or method".


    Please anyone help me in fixing this issue.

    Code:
    <script>
    
    function show() {
            var mycars = new Array();
            mycars[0] = "768,232,574,768.234";
            mycars[1]  = "abc, def, ghi, jkl,mno";
    
            for(var i=0; i<mycars[i].length; i++){
                mycars= mycars.split(",");
    
                document.getElementById('name')[0].value=mycars;
            }
    
        }
    </script>
    <form>
        <table class="cmn-table" id="t1" border="1"
            style="margin-left: 0.2em; margin-right: 0em">
            <tr>
                <th>Sl.No</th>
                <th>Source IP Address</th>
                <th>Destination IP Address</th>
                <th>Service and Port (TCP, UDP, etc.)</th>
                <th>Start Date</th>
                <th>Expiration Date</th>
            </tr>
            <tr>
                <td><input type="text" name="name11" id="s1" value="1" size="2"
                    readonly="readonly" /></td>
    
                <td><input type="text" name="name0" id="name" size="20">
                </td>
                <td><input type="text" name="name1" id="name1" size="20">
                </td>
                <td><input type="text" name="name2" id="name2" size="20">
                </td>
                <td><input type="text" name="name3" id="name3" size="15">
                </td>
                <td><input type="text" name="name4" id="name4" size="15">
                </td>
            </tr>
            <tr>
                <td><input type="text" name="name0" id="s2" size="2" value="2"
                    readonly="readonly" /></td>
                <td><input type="text" name="name" id="name5" size="20">
                </td>
                <td><input type="text" name="name1" id="name6" size="20">
                </td>
                <td><input type="text" name="name2" id="name7" size="20">
                </td>
                <td><input type="text" name="name3" id="name8" size="15">
                </td>
                <td><input type="text" name="name4" id="name9" size="15">
                </td>
            </tr>
        </table>
    
    </form>
    <input type="button" value="Click" onclick="show()">

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>123</title>
    <script type='text/javascript'>
    function show() {
    var mycars=[
    ['768','232','574','768','234'],
    ['abc','def','ghi','jkl','mno']
    ],ctr=0;
    for(var i=0;i<mycars.length;i++){
    for(var k=0;k<mycars[i].length;k++){
    document.getElementById('name'+ctr).value=mycars[i][k];
    ctr++;
    }
    }
    }
    </script>
    </head>
    <body>
    <form>
    <table class="cmn-table" id="t1" border="1" style="margin-left:0.2em;margin-right:0em">
    <tr>
    <th>Sl.No</th>
    <th>Source IP Address</th>
    <th>Destination IP Address</th>
    <th>Service and Port (TCP, UDP, etc.)</th>
    <th>Start Date</th>
    <th>Expiration Date</th>
    </tr>
    <tr>
    <td><input type="text" name="name11" id="s1" value="1" size="2" readonly="readonly" /></td>
    <td><input type="text" name="name0" id="name0" size="20"></td>
    <td><input type="text" name="name1" id="name1" size="20"></td>
    <td><input type="text" name="name2" id="name2" size="20"></td>
    <td><input type="text" name="name3" id="name3" size="15"></td>
    <td><input type="text" name="name4" id="name4" size="15"></td>
    </tr>
    <tr>
    <td><input type="text" name="name0" id="s2" size="2" value="2" readonly="readonly" /></td>
    <td><input type="text" name="name5" id="name5" size="20"></td>
    <td><input type="text" name="name6" id="name6" size="20"></td>
    <td><input type="text" name="name7" id="name7" size="20"></td>
    <td><input type="text" name="name8" id="name8" size="15"></td>
    <td><input type="text" name="name9" id="name9" size="15"></td>
    </tr>
    </table>
    </form>
    <input type="button" value="Click" onclick="show()">
    </body>
    </html>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Sorry. Nothing to add
    Last edited by 007Julien; 07-03-2013 at 06:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles