ciber Posted August 5, 2010 Share Posted August 5, 2010 Hi, Well I have finally ventured and decided I to use javascript to create a more friendly user interface. basically I need help on how I can do the following: <img src="generate.php?" style="float:right;> <form action="generate.php" method="post"> Name: <input name="name"><br> <select name="attribs"> <option value="atr1">Here 1</option> <option value="atr2">Here 2</option> <option value="atr3">Here 3</option></select><br> Gender: <input type="radio" name="gender" value="male">Male OR <input type="radio" name="gender" value="female">Female </form> So basically the code is an example of what im trying to achieve, but the part of the javascript im struggling with to find is how can I get the images source to update, so as the option are selected the variables are added to the arguments, ie I type my name in, when the form defocuses, the images src updates from generate.php? to generate.php?name=JohnDoe and so forth for the other fields. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 5, 2010 Share Posted August 5, 2010 To trigger an event when the user has finished typing there name and has clicked out of the text box you can use the onblur event handler. You could make it like this: <img src="generate.php?" id="image-generate" /> Name: <input name="name" id="name" onblur="javascript: document.getElementById('image-generate').src='generate.php?name=' + this.value;" /> You'd best make sure that in your generate.php file you perform checks on the input to ensure nothing nasty is coming through. Quote Link to comment Share on other sites More sharing options...
ciber Posted August 5, 2010 Author Share Posted August 5, 2010 will do, just one question what happens when another field, say gender is edited - wont that then remove the setting for name? Quote Link to comment Share on other sites More sharing options...
ciber Posted August 5, 2010 Author Share Posted August 5, 2010 nevermind I got another idea using this - thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.