Welcome Guest, Not a member yet? Register   Sign In
Javascript execution once single form field completed
#1

[eluser]JamesTaylor[/eluser]
How would i have some javascript execute once a particular field of a form has been filled in?

I currently have a form field which takes in a postcode, i then have a button which when pressed takes the postcode data executes some javascript and returns the latitude and longitude of the postcode. What i would like to achieve is for the javascript to be executed when the postcode form field is completed / cycled thro to the next field.

At the min my button which triggers the action has the following code:
Code:
<input type="image" value="Show Lat/Lng" o n C l i c k ="usePointFromPostcode(document.getElementById('postcode').value, showPointLatLng)" />
** NB - spacing added to onClick so it will display here.

and the form field which i want to trigger the javascript current is:
Code:
<label for = "postcode">Postcode:</label>
&lt;input id="postcode" name="postcode" type="text" value=""/&gt;
#2

[eluser]JamesTaylor[/eluser]
Ok, i've got this working by adding an onkeyup event to the formfield which points the javascript file which was being executed by the onclick event.

As a javascript beginner i'm not sure if this is the best practice for achieving my goal but it seems to be working as i wish.

I have tried to use onsubmit in the opening form tag but had a few problems, when using codeigniters form_open construction the onsubmit was causing errors in the code and breaking the page before it had loaded... probably my down to my lack of ability in passing the the code through appropriately! When i removed the codeigniter form generatoring tags and used tradition &lt;form&gt; tags the the javascript didn't seem to get processed prior to the submission, as i expected it to?




Theme © iAndrew 2016 - Forum software by © MyBB