admin管理员组文章数量:1434943
My website is trackschoolbus. You can see a login form at the top right. What I have set up is when a wrong input is given it redirects to home page with a parameter as ?er=1
i.e. /?er=1.
I need to display a error message when the error url es so I have written
<script type="text/javascript">
$(function(){
if (document.location.href.indexOf('er=1') > 0)
$("#display").show();
});
</script>
and the html is
<div id="display" style="display:none;">wrong input</div>
my login form is
<form name="login-form" id="login-form" method="post" action=".php">
<input name="LoginForm[username]" id="LoginForm_username" type="text" placeholder="Registered Email" value="" class="error" required/>
<input maxlength="30" name="LoginForm[password]" id="LoginForm_password" type="password" placeholder="Password" value="" class="error" required />
<input type="submit" onclick="this.disabled=true;this.form.submit();" name="yt0" class="btn-submit" value="Login" />
</form>
still it shows display none.
My website is trackschoolbus.. You can see a login form at the top right. What I have set up is when a wrong input is given it redirects to home page with a parameter as ?er=1
i.e. http://www.trackschoolbus./?er=1.
I need to display a error message when the error url es so I have written
<script type="text/javascript">
$(function(){
if (document.location.href.indexOf('er=1') > 0)
$("#display").show();
});
</script>
and the html is
<div id="display" style="display:none;">wrong input</div>
my login form is
<form name="login-form" id="login-form" method="post" action="http://www.trackschoolbus./vehicleTracking/index.php">
<input name="LoginForm[username]" id="LoginForm_username" type="text" placeholder="Registered Email" value="" class="error" required/>
<input maxlength="30" name="LoginForm[password]" id="LoginForm_password" type="password" placeholder="Password" value="" class="error" required />
<input type="submit" onclick="this.disabled=true;this.form.submit();" name="yt0" class="btn-submit" value="Login" />
</form>
still it shows display none.
Share Improve this question edited Apr 14, 2015 at 9:44 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Apr 14, 2015 at 9:33 MelvinMelvin 3832 gold badges13 silver badges43 bronze badges 11- Instead of Javascript you can use php condition – Sunil Pachlangia Commented Apr 14, 2015 at 9:35
- how can i add that ? – Melvin Commented Apr 14, 2015 at 9:36
-
Is the
$("#display").show();
insideif{ }
or the code formatting is so? – Shaunak D Commented Apr 14, 2015 at 9:36 -
1
<input type="submit" onclick="this.disabled=true;this.form.submit();"
is highly questionable. NEVER submit in a submit event and in some cases the submit event is stopped when the button is disabled. Instead hide it or replace it in the FORM's submit event – mplungjan Commented Apr 14, 2015 at 9:42 -
1
$("login-form").on("submit",function() { $("input[name='yt0']").hide();});
– mplungjan Commented Apr 14, 2015 at 9:49
3 Answers
Reset to default 4use php
<form name="login-form" id="login-form" method="post" action="http://www.trackschoolbus./vehicleTracking/index.php">
<input name="LoginForm[username]" id="LoginForm_username" type="text" placeholder="Registered Email" value="" class="error" required/>
<input maxlength="30" name="LoginForm[password]" id="LoginForm_password" type="password" placeholder="Password" value="" class="error" required />
<input type="submit" onclick="this.disabled=true;this.form.submit();" name="yt0" class="btn-submit" value="Login" />
<?php if (isset($_GET['er']) && $_GET['er'] == 1) {
echo '<div id="display">wrong input</div>';
}?>
</form>
You can use this code
if ($_REQUEST['er']==1)
{
echo '<script type="text/javascript">
$("#display").show();
</script>';
}
This is relatively simple in javascript.
Using the code snippet in this thread: How can I get query string values in JavaScript?
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (getParameterByName("er") == "1")
$("#display").show();
});
本文标签: javascriptdisplay a div based on url parameterStack Overflow
版权声明:本文标题:javascript - display a div based on url parameter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745636350a2667582.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论