prototypejs - Prototype or JQuery change the value of a hidden field? -


I am having some problems with the prototype changing the value of a hidden field.

Function:

  function remove_fields (link) {$ (link) .next ('input [type = hidden]'). Value = ''; Hide $ (link) .up ("OPEN_HOURS.");). }  

If I comment on $ (link) .next ('input [type = hidden]'). Value = '' ;; Hides the work. I get an error by trying to set the value:

  $ (link) .next ("input [type = hidden]") is undefined  
< P> Here's my HTML around the function call:

  & lt; Div class = "monday" & gt; & Lt; Div class = "open_hours" & gt; & Lt; Li & gt; & Lt; Label = "location_monday" & gt; Monday & lt; / Label & gt; Open: 06:29 PM - OFF: 04:21 PM & lt; A href = "#" onclick = "remove_fields (this); returnback;" & Gt; Remove & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "hidden alternative" id = "location_monday_open_input" & gt; & Lt; Input id = "location_monday_open" name = "location [monday_open]" type = "hidden" value = "18: 2 9" /> & Lt; / Li & gt; & Lt; Li class = "hidden alternative" id = "location_monday_close_input" & gt; & Lt; Input class = "off" id = "location_monday_close" name = "location [Monday_close]" type = "hidden" value = "16:21:00" / & gt; & Lt; / Li & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

Not sure what I'm doing wrong here? Thanks guys!

Answer by jQuery

Since you provided input with ID, you can use the ID selector

  $ ("# location_monday_close"). Val ('');  

If you do not want to get the hidden element based on ID, then you type

  $ (link) .closest ('div') Can use some. OPEN_HOURS '.) Seems (' input [type = hidden] ') val (.' ');  

In addition, if you want to hide the div with the square name open_hours, you can use

  $ ("div.open_hours") Are there.  

I have written the code for you. Click here (function () {Remove_fields ($ (this));}); function remove_fields (link) {var parentDiv = Link.closest ('div.open_hours'); parentDiv.find ('input [type = hidden]'). Val (''); ParentDiv.hide ();}}); & Lt; Div class = "monday" & gt; & Lt; Div class = "open_hours" & gt; & Lt; Li & gt; & Lt; Label = "location_monday" & gt; Monday & lt; / Label & gt; Open: 06:29 PM - Close: 04:21 PM Input ID =" location_monday_open "name =" location [ Monday_open] "type =" hidden "value =" 18:29:00 "/> gt;

& Lt; / div & gt;

edit

selector (Which is the anchor tag) immediately meet the following brothers No one brother to the anchor tag in your HTML.


Comments