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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.