porzant Posted October 29, 2006 Share Posted October 29, 2006 I was wondering if there was a way to use an input from a form as a Javascript variable? Think it may have something to do with HTML DOM. All help appreciated Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 29, 2006 Share Posted October 29, 2006 Yup, there is :)Make sure your element looks like this, note the id="":<input type="text" value="Input" id="txt" />This button makes it so that the text's value is sent to a javascript function, which I will just show you:<input type="button" value="Go!" onclick="val()" />Now, in the <head> section of your HTML document, add this:<script type="text/javascript">function val() { x=document.getElementById("txt").value; //Ok, now x contains the value of your form element.}</script>There ya go. Link to comment Share on other sites More sharing options...
porzant Posted October 30, 2006 Author Share Posted October 30, 2006 Thanks very much :)Is there anyway to do the opposite? i.e. print a variable into a text field on Submit? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now