Wednesday, 15 August 2012

javascript - get value from dynamic added text input -


I need to add some text input dynamically to my page:

  $ table =  

""; $ N = 0; $ Arrayform = array (); Forex currency ($ rslt $ as rows) {$ table = $ table "& Lt; div class = 'img-rounded row' style = 'margin-bottom: 2%' & gt; & lt; div class = 'col-lg-1' & gt; & lt; / div & gt; & Lt; div class = 'col-lg-4' & gt; & lt; input id = 'cap -' $ N. "'type =' text 'class =' ​​form-control 'value ='". $ Rows ['caption']. ' 'Gt; & lt; / div & gt; & lt; div class =' ​​col-lg-1 'id =' rightarrow '& gt; & lt; img id =' img- "$ N. '' Src = 'img / right-arrow.png' width = '45 'height =' 30 'alt =' '/ / gt; & Lt; / Div & gt; & Lt; Div class = 'col-lg-4' & gt; & Lt; Input id = 'val -'. $ N "" type = 'text' class = 'form-control' value = ''. $ Rows ['value']. '' & Gt; & Lt; / Div & gt; & Lt; Div class = 'col-lg-1' & gt; & Lt; Input type = 'button' id = 'btn -' $ N. '' \ ", \" ". \", [\ '\', $ '[' Caption ']. "\", \ "". $ Rows [' value ']. ]. "$ \ ['Id'] $ rows. \") 'Class =' ​​btn btn-danger 'value =' remove column '& gt; & lt; / div & gt; & lt; / div & gt; ; & Lt; div id = 'divrslt -'. $ N. "'class =' ​​line text-success 'style =' margin-left: 10%; Margin-bottom: 2% '& gt; & Lt; / Div & gt; "

The form element's ID is determined by the $ n variable and other strings.

I have written the following code to create the parameter list of the input code Javascript Function.

  $ array [$ rows ['caption']] = "cap -" $ N. "value, value -". $ N. ". Value, "; $ N ++;}  

and with the following code, I use the array built in the previous line as the parameters of the updatechartval () javascript function.

  $ table = $ table. "& Lt; Div square = 'line' style = 'margin-left: 4%' & gt; & Lt; Button type = 'button' class = 'btn btn-success' onClick =' updatechartval (".implode (", $ enthusiast). "\" ". $ _GET ['id']." \ ") 'Value =' Update '& gt; update & lt; / button & gt; & lt; / div & gt; ";  

And then I resonate it:

  counterattack $ table;  

The button code provided is:

  & lt; Button type = "button" class = "btn btn-success" onclick = "updatecharwall (cap-0.value, val-0.value, cap-1.value, wall-1.value, cap-2.value, val -2.value, cap-3.value, val-3.value, & amp; quot; 126 & amp; quot;) "value =" update "& gt; Update  

/ Div >

You are suffering from JavaScript equivalents of a SQL injection attack:

  [Kikot .. ] Onclick = "updatechartval (cap -0 .value, val-0.value, [.. snip ..] ^^^^^^^^^^^  

In the function call You need to quote your parameters, because the code is currently being interpreted / executed:

updateCharval (unknown / undefined variable "cap" zero 0.value, ...

form an integer There is no .value attribute, and since you are trying to reduce the undefined value attribute from that undefined variable, you are going to get a full back of stuff blowing in your face.

Your generator function should look even more:

  $ array [$ rows ['caption']] = "'cap' - $." Value ',' Val - '. $ N ", value' etc ... ^ --------------- - ^ ^ ---------------- ^  

Note additional quotes.


No comments:

Post a Comment