1
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href = "Jquery.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>

        var amount = new Array();
        var x;
        amount[0] = 1;

        function jobID(form){

            x = document.forms["JobIdForm"]["jobid"].value;
            return false;


        }

        $(document).ready(function(){
            jQuery('<div/>', {
                id: 'box',


                click: function(){
                    jQuery('<div/>', {
                        id: 'bob'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobb'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobbb'+amount.length
                    }).appendTo('#scroller');
                    $('#bob'+amount.length).css('width', '200px');
                    $('#bob'+amount.length).css('height', '80px');
                    $('#bob'+amount.length).css('background-color', '#F2F2F2');
                    $('#bob'+amount.length).css('border', '3px solid black');
                    $('#bob'+amount.length).css('margin-top', '10px');
                    $('#bobb'+amount.length).append(x);


                    $('#bobb'+amount.length).css('width', '130px');
                    $('#bobb'+amount.length).css('height', '80px');
                    $('#bobb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobb'+amount.length).css('border', '3px solid black');
                    $('#bobb'+amount.length).css('margin-top', '-86px');
                    $('#bobb'+amount.length).css('margin-left', '220px');
                    $('#bobb'+amount.length).append('hello');

                    $('#bobbb'+amount.length).css('width', '300px');
                    $('#bobbb'+amount.length).css('height', '80px');
                    $('#bobbb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobbb'+amount.length).css('border', '3px solid black');
                    $('#bobbb'+amount.length).css('margin-top', '-86px');
                    $('#bobbb'+amount.length).css('margin-left', '370px');
                    $('#bobbb'+amount.length).append('hello');

                    amount[amount.length] = 1;

                }


            }).appendTo('body');
            $('#box').append("Submit All");
        });
    </script>
</head>

<body>

    <header>
        <h1>Fill out Forms</h1>
    </header>
    <section>
        <div id="keys">
            <div id ="job">
                <p>Job ID</p>
            </div>
            <div id="date">
                <p>Date</p>
            </div>
            <div id="desc">
                <p>Description</p>
            </div>
        </div>
        <div id = "scroller" style="width: 700px; height: 400px; overflow-y: scroll;">

        </div>

        <form name="JobIdForm" action="" onsubmit="return jobID(this)" method="post">


            Job ID <input type="text" name="jobid">
            <input type="submit" value="Submit">    




        </form>
    </section>


</body>
</html>

2 Answers 2

4

Your scope of x is the issue. x is local to jobID. Declare x outside of the function.

var x;
function jobID(form){
    x = document.forms["JobIdForm"]["jobid"].value;
    return false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This didn't work either. I must have more problems with my code. But thanks for that fix anyway.
0

try something like this:

js

 $(function(){  //equivalent to $(document).read(function(){});
    //you are running "joID(form)" on submit now, but have it written/called right in the html.  i try to avoid that.
      $("form[name='JobIdForm']").submit(function(event){
//i did not see an actual form[action] value, so I preventDefault() to call that out
        event.preventDefault();
//we want the value in bob, so I have jQuery create a <div> and throw the input value between the element tags
        $("#bob").append($("<div>"+$(this).find("input[name='jobid']").val()+"</div>");
      });

    });

html needed to make the above work:

<form name="JobIdForm" action="" method="post">       
    <label>Job ID <input type="text" name="jobid"></label>
    <input type="submit" value="Submit">    

</form>

4 Comments

yes, j08691's post about the x var scope is why it is not working atm
I will post all of my code, I may have another problem in my code.
I wanted to avoid this because I think my code is a bit messy to be reading on your end
never mind the scope issue fixed the problem, i never noticed because I did not save my work before running. Rookie mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.