Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. auto checkbox based from url value using javascript/jQuery
  2. ?type=A&type=C or ?type=D
  3.        
  4. <form name="input" action="" method="post" ><br />
  5. Select Type: <br />
  6. <input type="checkbox" name = "type" value="A" /> A <br />
  7. <input type="checkbox" name = "type" value="B"  /> B <br />
  8. <input type="checkbox" name = "type" value="C"  /> C <br />
  9. <input type="checkbox" name = "type" value="D" /> D <br /> <br />
  10. <input type="submit" value="Submit" />
  11.        
  12. var i = document.location.href.lastIndexOf('?');
  13. var types = document.location.href.substr(i+1).replace(/type=/g,'').split('&');
  14. $('input[name="type"]').prop('checked',function(){
  15.      return $.inArray(this.value,types) !== -1;
  16. });
  17.        
  18. "type=A&type=C"
  19.        
  20. "A&C"   //after replace
  21.        
  22. ["A","C"]
  23.        
  24. $('input[value="A"]').prop("checked", true);