jackerybakery Posted August 31, 2010 Share Posted August 31, 2010 Hello I'm sorry that this is such a simple question, however I've been trying to solve it for ages and have decided I must have missed something and will be kicking myself when I hear the answer.I am trying to get my webpage to load an image from the input of the user from a form in HTML, for use by a JavaScript function. However I cannot obtain the value which the user types into the form. function watermark(){ var image = document.createElement("img"); x = document.input.img; image.src="./images/" + x.nodeValue+ ".jpg"; document.write(image.src) //Check what the output is ...etc...} <body><form name="input"><input type="text" name="img" /><input type="button" onClick="watermark()" value="Watermark" /></form></body></html> This is just one example of what I have tried. Other examples are .innerHTML; .getElementById("...").innerHtml (or) "".nodeValueand many more.Cheers,Jack Link to comment Share on other sites More sharing options...
thescientist Posted August 31, 2010 Share Posted August 31, 2010 try value to get the value of input elements.More importantly, are these paths intended to be from somewhere on the web or from the users computer? Link to comment Share on other sites More sharing options...
jeffman Posted August 31, 2010 Share Posted August 31, 2010 It's odd that you would combine modern DOM techniques with old-style syntax like document.input.imgusing document.write() on an existing document will cause the entire thing to be destroyed. Only ever use it while the document is still loading, not after. I guess it's okay as a check . . . Link to comment Share on other sites More sharing options...
jackerybakery Posted August 31, 2010 Author Share Posted August 31, 2010 try value to get the value of input elements.More importantly, are these paths intended to be from somewhere on the web or from the users computer?Its ok, its just a script for my own use, so will only access my own files. It will also only read the files.Thanks for your help. Link to comment Share on other sites More sharing options...
jackerybakery Posted August 31, 2010 Author Share Posted August 31, 2010 It's odd that you would combine modern DOM techniques with old-style syntax like document.input.imgusing document.write() on an existing document will cause the entire thing to be destroyed. Only ever use it while the document is still loading, not after. I guess it's okay as a check . . .Yeh, just put it in there later as a check and will remove it when I've figured out the syntax I need. The old-style syntax I found on this website so decided to try it.Can you suggest a good and up to date line of code for retrieving the value the user types?Thanks Link to comment Share on other sites More sharing options...
jackerybakery Posted August 31, 2010 Author Share Posted August 31, 2010 ok set the input element's id to "imageName"then changed the code to: image.src="./images/" + document.getElementById("imageName").nodeValue + ".jpg"; which returned file:///C:/Users/Jackery/Documents/web/rebeccArt/images/null.jpg Also tried: image.src="./images/" + document.getElementById("imageName").innerHTML + ".jpg"; Which returned: file:///C:/Users/Jackery/Documents/web/rebeccArt/images/.jpg Link to comment Share on other sites More sharing options...
jeffman Posted August 31, 2010 Share Posted August 31, 2010 Give the input an id. Then it's justvar uservalue = document.getElementById("the_id").value;The value property of form inputs is actually very old, though not old fashioned. Link to comment Share on other sites More sharing options...
jackerybakery Posted August 31, 2010 Author Share Posted August 31, 2010 Give the input an id. Then it's justvar uservalue = document.getElementById("the_id").value;The value property of form inputs is actually very old, though not old fashioned.Thanks very much Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.