Javascript update input element

I have quite a large IF statement which needs to update another form element depending on which scenarion only Its not working, By not working I mean its not updating the form element nor executing any more code in that statement.

My code is...

window.onload = function() { new Dragdealer('magnifier', { steps: 10, snap: true, callback: function(value) { if(value == 0) { alert('1'); } else if(value == 0.1111111111111111) { alert('2'); } else if(value == 0.2222222222222222) { alert('3'); } else if(value == 0.3333333333333333) { alert('4'); } else if(value == 0.4444444444444444) { document.getElementById(coff_upd).value = '5'; alert('5'); } else if(value == 0.5555555555555556) { document.getElementById(coff_upd).value = '6'; alert('6'); } else if(value == 0.6666666666666666) { document.getElementById(coff_upd).value = '7'; alert('7'); } else if(value == 0.7777777777777778) { document.getElementById(coff_upd).value = '8'; alert('8'); } else if(value == 0.8888888888888888) { document.getElementById(coff_upd).value = '9'; alert('9'); } else { document.getElementById(coff_upd).value = '10'; alert ('10'); } } }); }

and the input...

<input type="text" value="<?php echo $user_curr_coff;?>" name="coff_upd" id="coff_upd" />

-------------Problems Reply------------

Don't know if you cut and pasted your code but: document.getElementById(coff_upd).value = '5'; won't work as js is looking for a variable named coff_upd. You need to put quotes around it: document.getElementById("coff_upd").value = '5';

Category:javascript Views:5 Time:2011-06-02
Tags: javascript

Related post

  • JavaScript: add input element to current div 2012-04-21

    I have a javascript function which adds a div with three inputs to the page and a link to add more inputs to the same div (Imagine that user doesn't know how many fields there will be so he can add them dynamically). var div=document.createElement("d

  • Passing input values into an action from a javascript created input elements 2015-02-02

    Is it possible to add to the web page params object dynamically via a js once the web page is displayed and from input values from elements created dynamically within a js? If so it would enable me to transfer web data into a single action. Here is s

  • How to handle programmatic change of the input element state in javascript 2008-12-30

    I've faced strange problem. While user change of check box input element on form produces adequate event programmatic change don't. How should I face this challenge? Code following: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://

  • Updating cloned elements in javascript? 2012-03-23

    Say I have text input A. I create a new form element, F, in javascript, but do not attach it to the DOM. I then attach an input B (clone of input A) to F. Input B is supposed to mimic input A so I'll use an event listener to change the value of B bas

  • Clone a file input element in Javascript 2009-01-06

    I have a file input element that needs to be cloned after the user has browsed and selected a file to upload. I started by using obj.cloneNode() and everything worked fine, that is until I tried using it in IE. I've since tried using jQuery's clone m

  • Need File Input Element cloned from 1 form into another via PHP & Javascript 2009-05-17

    Ok, I have an in template function that get's submitted via method="POST". But I can't submit this normally, since this is all I want submitted, and there is already a tag defined above the code and than below the code, closing the form with that mus

  • JavaScript: Visibility error in Internet Explorer when setting focus on an input element 2009-09-24

    This may be the most obscure bug I have yet encountered in many years of working with JavaScript and any version of Internet Explorer. We're using YUI 2.7 for some of the (non)convenience methods. Sigh, what I would do for jQuery.... This is affectin

  • Checking input elements on Firefox with JavaScript 2009-11-28

    I'm developing an extension, which listens to click events on elements. Now I have two questions: Is there a convenient way to detect whether an element is an input element? Like input, textarea in HTML, and textbox in XUL. If the user clicked on an

  • JavaScript: How to get value of sender input element from keyup event? 2010-02-28

    I need to capture the keyup event to provide live validation when user is typing in an input (change event fires only when the input loses focus). I am having trouble getting the edited value of the input that fired the evnt. The code also runs on ti

  • Get text input element having cursor (caret) in JavaScript 2011-03-11

    How to Get the text element (or its id) in which there is caret? --------------Solutions------------- document.activeElement will give you this in most browsers. Edit: Guess, I completely misunderstood the word "caret" as it stands for "cursor" in th

  • Input element in javascript 2011-07-08

    How to set the size or width of an input element in javascript. I am using input_obj.size= '40%'; But, it is not working. --------------Solutions------------- You should use style attribute: = '40%'; You set the size as per your

  • javascript change event on input element fires on only losing focus 2011-08-18

    I have an input element and I want to keep checking the length of the contents and whenever the length becomes equal to a particular size, I want to enable the submit button, but I am facing a problem with the onchange event of javascript as the even

  • How to get all input elements from page using only plain JavaScript? 2011-11-09

    How to get all input elements from page using only plain JavaScript ( I have only three ) ? I cannot use any framework because I need to use this in android WebView. --------------Solutions------------- you could use document.getElementsByTagName("in

  • Issue with spry validation from a dynamically updated input field vai javascript 2011-11-21

    I have a form on my website that uses spry validation widgets. I have recently added a date feature that uses 3 drop down boxes (day, month, year). I've used the onchange feature of the selection boxes to update a text field with the date and used sp

  • Triggering events on input elements using javascript 2012-03-16

    I want to trigger an event hen the value of an input element using javascript.The value of the input element is changed using script ,and is not typed.I know that the onChange event fires not after the value is changed ,but after the value is changed

  • Use JavaScript to place cursor in a Chrome text input element 2010-05-18

    I've been working on sending text to an input element in Chrome and I noticed that, unlike in IE or FF, calling .focus() does not put the cursor in the text area. So does anyone know of an alternative for placing the cursor on a Chrome input element?

  • Does javascript cache DOM elements? 2009-02-13

    I'm using mootools to toggle the display (and existence) of two DOM elements in one of my forms. Then, I am using javascript to validate the form to make sure that all of the required fields were filled in. The problem is that the the browser seems t

  • Javascript - form select element open url in new window and submit form 2009-02-19

    UPDATED - please read further details below original question I have a select form element with various urls, that I want to open in a new window when selected - to do this I have the following code in the element's onchange event:

  • How can I monitor the value of a hidden input element? 2009-04-28

    I have a SELECT element which adds its value to a hidden INPUT via Javascript every time an OPTION is clicked (along with a visual representation of each selection) and I'd like to be able to monitor changes for another Javascript function. For the s

Copyright (C), All Rights Reserved.

processed in 0.085 (s). 11 q(s)