0

I am new to javascript. I just want to create a list with textbox and label in a row.

So that I created a ul tag with id cstList.

and called a function listData() on the onclick event

Inside that I am trying to create a input tag inside a div tag.

But i am getting error when trying to run this.

Here is my code:

function listData()
    {       
        //var a = sessionStorage.getItem('id');
        if(sessionStorage == null)
        {
            alert("Session storage not supported here");
        }
        else
        {
            var ss = sessionStorage.getItem('id');
            alert("storage value is: "+ss);
        }
    var rows = prompt('Please type in the number of required rows');
    var listCode = '';

    for (var i = 0; i < rows; i++) {
        var listID = 'list_' + i.toString();
        var divID = 'div_' + i.toString();      
            listCode += '<li id="' + listID + '" onclick="itemClicked(this.id);"><div id = "'+ divID + '"> <input type= 'text' id= 'boltQTY' name= 'boltQTY' value = 'abc' size="5"/> </div></li>';
    }
    document.getElementById('cstList').innerHTML = listCode;
    }

This is the above line where i am getting error: Unexpected Identifier

 listCode += '<li id="' + listID + '" onclick="itemClicked(this.id);"><div id = "'+ divID + '"> <input type= 'text' id= 'boltQTY' name= 'boltQTY' value = 'abc' size="5"/> </div></li>';
3
  • looks like you forgot a bunch of plus signs when concatenating the string Commented Nov 16, 2012 at 4:29
  • ok so i should go with the double quote.right? Commented Nov 16, 2012 at 4:31
  • yes. that is correct :) Commented Nov 16, 2012 at 4:33

2 Answers 2

1

You are using single quotes and that is breaking the string.

<input type= 'text' id= 'boltQTY' name= 'boltQTY' value = 'abc' size="5"/>

should be:

<input type= "text" id= "boltQTY" name= "boltQTY" value = "abc" size="5"/>
Sign up to request clarification or add additional context in comments.

2 Comments

thts really nice. I got the solution quickly. Thanks a lot
i met with one more issue here. the input boxes are placed perfectly. but why the string is not getting entered here. I removed onclick from this. then to its not getting input
1

That has to be double-single-single-double

listCode += "<li id='" + listID + "' onclick='itemClicked(this.id);'><div id = '"+ divID + "'> <input type='text' id='boltQTY' name='boltQTY' value='abc' size='5'/> </div></li>";

variable = "string" + var1 + "string=' " + var2 +"' ";

Simply make sure plus sign (+) is in between double quotes ("")

1 Comment

i met with one more issue here. the input boxes are placed perfectly. but why the string is not getting entered here. I removed onclick from this. then to its not getting input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.