Skip to content

Instantly share code, notes, and snippets.

@irasally
Created January 31, 2012 02:54
Show Gist options
  • Save irasally/1708418 to your computer and use it in GitHub Desktop.
Save irasally/1708418 to your computer and use it in GitHub Desktop.
値の入っている要素のみをパラメーターとしてgetURLを生成する
function submit(form, action){
var params = '';
var el;
var i = form.elements.length;
while(i--){
el = form.elements[i];
if(el.type !== 'submit' && el.value !== ''){
if((el.type === 'checkbox' || el.type === 'radio') && !el.checked) continue;
if(params.length > 0) params += '&';
params += el.name + '=' + el.value;
}
}
document.location.href = action + '?' + params;
}
@irasally
Copy link
Author

もう少し良いコードを考える

@irasally
Copy link
Author

irasally commented Feb 9, 2012

パフォーマンスが良くなかったところを教えてもらったのでなおす

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment