Jump to content

Javascript for Image Source Updating


ciber

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/209863-javascript-for-image-source-updating/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.