javascript - Trying to change value of my submit input on form submit -
i have list of posts in page, , have form search posts.
this form:
<form action="" method="post"> <input type="text" name="search" onclick="if(this.value=='search:')this.value=''" onblur="if(this.value=='')this.value='search:'" value="search:" /> <input type="submit" value="search" class="search" name="sendform" /> </form> and then, when form submited values store session sql status statment , list of news have title value wrote in input.
and then, if submit form without value unset session , list of news again.
this php:
if(isset($_post['sendform'])){ $search = $_post['search']; if(!empty($search) && $search != 'search:'){ $_session['where'] = "where title '%$search%'"; } else{ unset($_session['where']); header('location: dashboard.php?exe=posts/index'); } } and need alter value of input sumbit when submit form.
at first, submit value "search", , when click in want alter value "clear". , when click in "clear" want alter "search" again.
do know how can correctly?
i tried @ first, didnt work fine:
<input type="submit" value="search" onclick="if(this.value=='search:')this.value='clear" name="sendform" /> and im trying using toogle, not working correctly.
$(".search").toggle(function (){ $(this).val("search"); }, function(){ $(this).val("clear"); }); demo
toggle() - click deprecated - reference, current toggle() jquery hides element.
use preventdefault() preventing form submit, if need.
check code,
var clear = true; $('.search').click(function(e){ e.preventdefault(); //if required if(clear){ $(this).val('clear'); clear = false; } else{ clear = true; $(this).val('search'); } }); javascript php jquery
No comments:
Post a Comment