javascript - Expected expression, got end of script -
so have below code in header of webpage:
<script type="text/javascript"> var counter = 2; function addnewitemfield(divname) { var newdiv = document.createelement("div"); newdiv.id = "item_listing_" + counter; newdiv.innerhtml = "<label for=\"item_" + counter + "\">item: </label><br />"; newdiv.innerhtml += "<input type=\"text\" id=\"item_" + counter + "_category\" list=\"list_categories\" name=\"items[]\">"; newdiv.innerhtml += "<input type=\"number\" id=\"item_" + counter + "_amount\" mine=\"0.00\" step=\"0.01\" value=\"0.00\" name=\"amounts[]\"><br />"; document.getelementbyid(divname).appendchild(newdiv); counter++; } </script>
i try calling using button, syntax error stating "expected expression, got end of script."
i've ran through linter , found no errors, i've reviewed hundred times , cannot find fault is. hate post code , ask "why doesn't work?" don't have idea what's going on i'm @ loss on how ask proper question it.
update
here associated piece of html furhter down page function call made , peices being manipulated reside:
<div id="item_listings"> <div id="item_listing_1"> <label for="item_1">item: </label><br /> <input type="text" id="item_1_category" list="list_categories" name="items[]"> <input type="number" id="item_1_amount" min="0.00" step="0.01" value="0.00" name="amounts[]"><br /> </div> </div> <br /> <input id= "add_new_item" type="button" onclick="javascript:addnewitemfield("item_listings")" value="add item">')
onclick="javascript:addnewitemfield("item_listings")"
full of errors.
you cannot mix-and-match double quotes way. need use single quotes inside double quotes or you're stopping html element's attribute early.
right now, parses as
<input id= "add_new_item" type="button" onclick="javascript:addnewitemfield("
... followed bunch of garbage.
you need use single quotes:
<input id= "add_new_item" type="button" onclick="javascript:addnewitemfield('item_listings')" value="add item">
Comments
Post a Comment