开发者

jquery and dynamic forms help?

开发者 https://www.devze.com 2023-04-01 01:23 出处:网络
I\'m very new to jquery, and I\'m trying to make a dynamic form in the following manner (and its not working). I want the form to have an initial value of \"hello\" as stated in the header region.

I'm very new to jquery, and I'm trying to make a dynamic form in the following manner (and its not working). I want the form to have an initial value of "hello" as stated in the header region.

I understand that you can do this easily with html (with the value parameter), but I have a much larger goal in mind that requires the value to be dynamic.

Anyway, I just can't seem to get it to work, so help please. Thank you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTM开发者_高级运维L 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Logging In Test</title>
    <script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js">
    var value = "hello";
    $('#login [name=firstname]').val(value)
    </script>
</head>
<body>
<form id="login">
    <input type = "text" name="firstname">
</form>
</body>
</html>

Thank you.!


use $(document).ready(); http://api.jquery.com/ready/
like

$(document).ready(function(){
    var value = "hello";
    $('#login [name=firstname]').val(value)
});

to set initial values after document fully loads and DOM is created properly


there is a problem with how and when you insert jquery try the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Logging In Test</title>
</head>
<body>
<form id="login">
    <input type = "text" name="firstname">
</form>



<script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js"></script>
<script type = "text/javascript">
    var value = "hello";
    $('#login [name=firstname]').val(value)
</script>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号