Monday 15 June 2015

php - Select values retrieve -


Dear friends from this function, I retrieve the values ​​selected by my users and I use it in the hidden field To keep the form:

  & lt; SCRIPT type = "text / javascript" & gt; Function UpdateHard (SL) {var f = document.contract; F.sel_value.value = sel.options [sel.selectedIndex] .value; } & Lt; / SCRIPT & gt;   

The problem is that my selection is within the time cycle and therefore it is repeated that the JS function determines the selected value only in the first selection. I need to add a loop to the function, but I do not know where to put it this is my form:

  & lt; Form action = "update.php" method = "post" name = "contract" & gt; & Lt; Table class = "myp-table" & gt; & Lt; TR & gt; & Lt; Td square = "head-act" & gt; Contract & lt; / Td> & Lt; / TR & gt; & Lt ;? Php do {? & Gt; & Lt; TR & gt; & Lt; Td class = "head-act" & gt; & Lt; Select name = "player contract []" onchange = "updateHidden (this)" & gt; & Lt; Option value = "0" & ​​lt ;? Php if ((Strcmp (0, $ row_datacontract [playercontract ']))) {resonant "select = \" selected \ "";}? & Gt; & Gt; 0 & lt; / Options & gt; & Lt; Option value = "1" & lt ;? Php if (! (Strcmp (1, $ row_datacontract [playercontract ']))) {resonant "select = \" selected \ "";}? & Gt; & Gt; 1 & lt; / Options & gt; & Lt; Option value = "2" & lt ;? Php if ((Strcmp (2, $ row_datacontract ['playercontract'])) {resonant "selected = \" selected \ "";}?? & Gt; & gt; 2 & lt; / option & gt; & lt; Option value = "3"  & lt; td & gt; Lt; input name = "id []" type = "hidden" value = "& lt ;? php echo $ row_datacontract ['id'] ;? gt; / gt; & gt; & lt; / td & gt; & Lt; / tr & gt; & lt ;? php} while ($ row_datacontract = mysql_fetch_assoc ($ datacontract));? Gt; & lt; tr class = "zebra"> gt; & lt; td & gt; input >  & lt; / TR & gt; & lt; / table & gt; & lt; / form & gt; < / Code>  

Thank you.

The problem is that you have N & lt; Input type = "hidden" name = "sel_value" & gt; , how will it be known that name = "sel_value" to change? It would be best to change sel_value [] or unique names.

However, your function can be easily changed by using the

  function update (SEL) {sel.nextElementSibling.value = sel.options [sel.selectedIndex ] .value; }   

See this jsFiddle -

No comments:

Post a Comment