tags:

views:

512

answers:

2

Using the Dojo Toolkit I am trying to pass the value from textbox to an alert on click. I tried attr to obtain value inside the function helloPressed(), but I am not even able to reset the textbox value when I tried the other way.

I am new to the programming world.

function helloPressed() 
{
    var gt =  dojo.attr("htext1","value");
    alert(gt).show();
}

<input dojoType="dijit.form.textbox"  name="name1" widgetId="htext1" 
 dojoType="dijit.form.TextBox" intermediateChanges="true" value="hello"  
 trim="true" propercase="true" /></input>
<button dojoType="Button" widgetId="helloButton"
 onClick="helloPressed()">Click !</button>

I tried other combinations as well, but no success :(

A: 

Add id="htext1" among the attributes of your input tag; dojo.attr(somestring, ...) searches for a DOM node with id == somestring, not for one with widgetId == somestring.

BTW, use just alert(gt) -- that .show() is just an error. I recommend using the firefox browser with the firebug plug-in for web development, this way you will see appropriate error messages in firebug's console to help you develop correct HTML, CSS, Javascript, and so on.

Alex Martelli
thanks Alex, I tried thisvar ht = dojo.byId('htext1'); ht.dojo.attr("new value"); alert(gt).show();and var ht = dojo.widged.byId('htext1'); ht.dojo.attr("newsometext"); but nothing happens
sorry , missed the second part. I will try firebug now. Thanks again for helping me
Did you add 'id="htext1"' to the input tag? That's the crucial part of my answer and I don't see you acknowledging it!
Alex Martelli
A: 

You can try to do something like that:

var gt = dijit.byId("htext1").attr("value");
alert(gt);

dijit.byId() retrieves a widget object, and you can call attr() on it.

I assume that alert() is a standard JavaScript function. If this is correct, you don't need (and actually cannot) use nay properties on it.

Eugene Lazutkin
I noticed that if I try to retrieve a widget object, the alert stops responding. If I comment it and instead just pass a variable to the alert it works. I tried your code, but still it doesnot do anything. What if I just want to change the textbox value on click ?
That's bizarre --- I cannot imagine how working with widget can interfere with alerts. Can you post a minimalistic example somewhere?
Eugene Lazutkin