Tuesday, 6 August 2013

Assign variable to form input value and print using jquery

Assign variable to form input value and print using jquery

I'm using a form input box like so:
<form name="JobIdForm" action="" onsubmit="return jobID(this)" method="post">
Job ID <input type="text" name="jobid">
<input type="submit" value="Submit">
</form>
The javascript function that runs when the submit button is pressed is here:
function jobID(form){
var x = document.forms["JobIdForm"]["jobid"].value;
return false;
}
I then use jQuery to print the x vairable onto one of my divs:
$('#bob').append(x);
This doesn't work. Could someone explain to me why it doesn't and how I
can fix it. Thanks for any answers in advance.

No comments:

Post a Comment