javascript - Do nothing on empty input - combinate with dynamic action on form -
what want when type in input, depending button click, change path of action in form. @ half way achieve (i think)....check out make till now
function onsubmitform() { if(document.pressed == 'log as') { document.myform.action ="log-as.html"; } else if(document.pressed == 'log int') { document.myform.action ="log-as-int.html"; } return true; }; <form name="account" onsubmit="return onsubmitform();"> <input type="text" name="user" id="user"> <input type="submit" name="account" onclick="document.pressed=this.value" value="log as" /> <input type="submit" name="account" onclick="document.pressed=this.value" value="log int" /> </form> and maybe found solution this, don't know how combinate two...
$('#search-form').submit(function(e) { if (!$('#user').val()) { e.preventdefault(); } });
you can same thing using code:
first of
nameattribute of form ,input type submitsame. must unique.
<form name="account" id="account" action=""> <input type="text" name="user" id="user"> <input type="submit" name="account_submit1" onclick="document.pressed=this.value" value="log as" /> <input type="submit" name="account_submit2" onclick="document.pressed=this.value" value="log int" /> </form> and
$(document).ready(function () { $("#account").submit(function(e){ alert($.trim($("#account [type='submit']:focus").val())) if($.trim($("#account [type='submit']:focus").val()) == "log as"){ $("#account").attr('action',"log-as.html"); }else{ $("#account").attr('action',"log-as-int.html"); } }); }); updated code according discussion:
$(document).ready(function () { $("#account").submit(function(e){ if (!$('#user').val()) { e.preventdefault(); } if($.trim($("#account [type='submit']:focus").val()) == "log as"){ $("#account").attr('action',"log-as.html"); }else{ $("#account").attr('action',"log-as-int.html"); } }); });
Comments
Post a Comment