Pass the textbox value to javascriipt function

Pass the textbox value to javascriipt function

  
i created the function MsgPhoneNo(Val) in Javascript Editor of the webpage.
In my web page i have textbox control during the lostfocus of the control i should passed the typed value to the javascript function.
for that i worked following base like Control name is "UserDetails_PhoneNo"
1.Passed the Control name and used   document.getElementById('UserDetails_PhoneNo').value;
2.Passed MsgPhoneNo('UserDetails_PhoneNo.Id') and used  document.getElementById('UserDetails_PhoneNo.Id').value;

But i did get the value of the textbox.
Can u please tell us how to get the value from the textbox during lastfocus and send to javascript function.
Hi Devaraj,

You're probably missing the quotes
Your javascript function should be somthing like this:
function MsgPhoneNo(phoneNbrId) {
  var elem = document.getElementById(phoneNbrId);
  if(elem)
    alert(elem.value);
}

phoneNbrId is a string with the client id of the control, so do not surround it with quotes.
Now you need to call it with the actual clientId, so on the onblur Extended Property of your textbox call it like 
"MsgPhoneNo('" + UserDetails_PhoneNo.Id + "');return false;"
where you get the client id of the textbox, enclose with in a javascript string and pass it on to the javascript function you defined.

I've attached a sample oml that exemplifies that.



 
Hi again!

I also have a problem with a textarea and javascript. I want to limit the characters so I use the extended properties: onkeyup and onkeydown and the value is:
"<script language='javascript' type='text/javascript'>
function limitText("+limitField.Id+","+Get...LimitCharacters+")
{
    if ("+limitField.Id+".value.length>= "+Get...LimitCharacters+") 
    { 
    "+limitField.Id+".value = "+limitField.Id+".value.substring(1, "+Get...LimitCharacters+"); 
    }
}
</script>"
Can someboby tell me what is wrong with this approach?

Thanks 
Well,

At first glance, I would assume that
"+limitField.Id+".value.length
doesn't quite work, because when that expression is evaluated, it is

that_specific_widget_id.value.length

and given that that_specific_widget_id is a string and not the widget itself, it should give an exception. You will need to retrieve the widget using it's ID.

Either you use

document.getElementById('"+limitField.Id+"').value.length

or, if you're using another Javascript framework such as jQuery, they sometimes have their own methods to do so.

Notice the ' " in the syntax.

A tip for you when dealing with Javascript is to use Firefox and its extension Firebug, which lets you test this and debug it in runtime.

I hope this helps. Let us know how it goes!

Regards,

Paulo Tavares
It's done!

The solution is to use the document.getElmentById like you suggested and in the value:
"if (document.getElementById('"+limitField.Id+"').value.length >="+ Get...LimitCharacters+") {
        document.getElementById('"+limitField.Id+"').value = document.getElementById('"+limitField.Id+"').value.substring(1, "+ Get...LimitCharacters+");
    } "
in other words without the script tags and "function limittext".

Thanks!
Hi,
 I have 3 text box one is borrower second is co-borrower and third is total .
I mean the logic is like this 3+2=5 but if i passed 3 in borrower textbox i'm getting the same value for
co-borrower and total also.Can anyone explain me.
Hi Chandrasekar,

Can you explain how you are retrieving the wrong value? 
I cannot help you with so little detail, and I reckon most community members will have the same problem.


Hi,
 Please see my screenshot .For all the text box it is retriving the same value,
I need this logic in total=Borrower + co-borrower.
Can you explain how you are retrieving the value? 
Manually we are entering the value and checking it.
When I say "how are you retrieving the value?", I mean "what code are you writing to update the value?".
In other words, what is the code that is causing the wrong value to be displayed?
Hi,
on blur =Income_Monthlyincome3.Id = Income_Monthlyincome4.Id + Income_Monthlyincome2.Id
this is the logic i'm implying.

Ok can u say 

 How to add two values and display the sum in another textbox using jquery.

After asking 3 times, you are still not posting any code. It's hard to help you like that...
Being more specific, what are you assigning to the onblur extended property of each of your widgets?

e.g. if i set onblur of my_input widget to 
"$('#" + my_copy.Id +"').val($('#" +my_input.Id + "').val())"
it will copy my_input to my_copy on lose focus.
If still not working for you, I suggest you to debug the JavaScript code in the browser.
Hi,
onblur="$('#" +Income_Monthlyincome3.Id + "').val(Income_Monthlyincome4.TypedValue + Income_Monthlyincome2.TypedValue).val());".

This is what i'm passing in the extended property.

Hi,

If u see in my attachment i'm setting the onblur property in the total text box.

 
As I commented on the other forum post you entered, the expression Income_Monthyincome4.TypedValue is within quotes. This implies that it won't be evaluated by OutSystems Platform, and it will be evaluated only on the browser. 
The browser doesn't know the identifier Income_Monthlyincome4, and so your code fails.
In the first part of your expression, you are using 
"$('#" +Income_Monthlyincome3.Id + "')
instead of simply
Income_Monthlyincome3

in order to generate JavaScript that the browser can understand.
You just need to apply the same logic to the other identifiers in your expression.
Well, if you want to use JavaScript and JQuery, you have to learn it first.