1

am using as follows

 <input type="text" value="<?php echo empty($this->session->store['actual_info']['actual_total_marketing_budget']) ? '' : $this->session->store['actual_info']['actual_total_marketing_budget']; ?>"  readonly name="actual_total_marketing_budget" readonly id="actual_total_marketing_budget"  size="30" style="height:20px; " onFocus="total_marketing_budget()"/></td>

here the issue when clicking on the textbox only it is getting or changing value i need the value without clicking on text box what i have to do. someone help me please

user2739848
  • 105
  • 1
  • 3
  • 12
  • Please post the actual HTML, not the PHP code. Also you could create a [fiddle](http://jsfiddle.net/). – MCL Sep 04 '13 at 09:31
  • please post ur js function total_marketing_budget() and also specify when you need the value? – Harry Bomrah Sep 04 '13 at 09:31
  • Are you looking for how to get the new value when the value was changed. Is it?? – Allen Chak Sep 04 '13 at 09:34
  • yes am using the following function function total_marketing_budget() { var a = document.getElementById("actual_total_advertising").value; var b = document.getElementById("actual_total_sales_promo").value; var c = document.getElementById("actual_total_coop_mark").value; var d = document.getElementById("actual_total_press_pub_relations").value; var t = parseFloat('0'+a)+ parseFloat('0'+b)+ parseFloat('0'+c)+ parseFloat('0'+d); document.getElementById("actual_total_marketing_budget").value = t; } – user2739848 Sep 04 '13 at 10:01

3 Answers3

0

Try doing:

document.getElementById('actual_total_marketing_budget').value

See it here in action. However, a similar question was answered here.

Community
  • 1
  • 1
Thierry
  • 746
  • 13
  • 15
0

You have written the function to get the value of textbox, in onFocus event.

Change it to on document load like

<script>    
(function() {
        var textBox = document.getElementById('actual_total_marketing_budget').value
    })();
</script>

Check this in JSFiddle

Praveen
  • 55,303
  • 33
  • 133
  • 164
  • excuse me it is getting value from this function function total_marketing_budget() { var a = document.getElementById("actual_total_advertising").value; var b = document.getElementById("actual_total_sales_promo").value; var c = document.getElementById("actual_total_coop_mark").value; var d = document.getElementById("actual_total_press_pub_relations").value; var t = parseFloat('0'+a)+ parseFloat('0'+b)+ parseFloat('0'+c)+ parseFloat('0'+d); document.getElementById("actual_total_marketing_budget").value = t; } – user2739848 Sep 04 '13 at 09:59
  • @user2739848 Have you checked my fiddle http://jsfiddle.net/wVMKN/? you will get some idea. otherwise create a fiddle and share it here. – Praveen Sep 04 '13 at 10:20
  • excuse me can we readonly textboxes for onChange. Whether it will work or not – user2739848 Sep 04 '13 at 10:37
0

you could do it like this;

<input type ="text" value="...." id ="actual_total_marketing_budget">


<script type="text/javascript">
function actual_total_marketing_budget(){
var textbox = document.getElementById('actual_total_marketing_budget');

//the function body is the same as you have defined sue the textbox object to set the value
}

actual_total_marketing_budget();
</script>

Here notice that I have called the function actual_total_marketing_budget() after defining it that changes the value of the textbox once the page has loaded.

Shikhar Subedi
  • 606
  • 1
  • 9
  • 26