user994991
user994991

Reputation: 47

Javascript: assign/pass a value to a inputbox

I have this javascript for slider, my problem is i cant assign/pass the value of the slider to a inputbox. I already tried using this scripT "document.getElementByID('total').value = pos" in my javascript, but it didnt pass anything. any idea guys? Thanks in advance!

HTML CODE:

< input type="hidden" id="total" value="" style="border:0; color:#f6931f; font-weight:bold;" runat="server" />   

JAVASCRIPT FUNCTION:

window.addEvent('domready', function() 
    {
        var mySlideB = new Slider($('slider_gutter_1'), $('slider_knob_1'),         $('slider_bkg_img_1'),
        {
            start: 1,
            end: 100,
            offset: 10,
            onChange: function(pos)
            {
                if (pos <= 10) {
                    $('slider_desc_value').setHTML("Not Important");
                }
                else if ((pos >= 11) && (pos <= 40)) {
                    $('slider_desc_value').setHTML("Partially Important");
                }
                else if ((pos >= 41) && (pos <= 60)) {
                    $('slider_desc_value').setHTML("Important");
                }
                else if ((pos >= 61) && (pos <= 85)) {
                    $('slider_desc_value').setHTML("Very Important");
                }
                else if (pos > 85) {
                    $('slider_desc_value').setHTML("Critical to our business");
                }

                $('slider_current_val').setHTML(pos + ' %');
                $('testjp').setHTML(pos);    

                                    // THIS IS NOT WORKING, HELP?
                **document.getElementById('total').value = pos;**

                                    //This work c/o Ravi. THanks!
                                    document.forms["form1"]["total"].value = pos;

            }
        }, null).setMin(1);

        $('slider_current_val').setHTML(100 + ' %');
    });

Upvotes: 0

Views: 480

Answers (5)

ravi404
ravi404

Reputation: 7309

Instead try this, give a name to your input and your form i.e

<form name="form"><input type="hidden" name="total"/></form>

and try this

document.forms["form"]["total"].value = xxx;

Upvotes: 2

Sitnam
Sitnam

Reputation: 164

The input has a runat="server" property, because of this the ASP.Net engine could be assigning the ID.

Just as a suggestion view the source of you application and you will see if the ID has changed.

if so the fix is easy.

document.getElementById('<%= total.ClientID %>').value = pos

or as the other two answers suggested

$('#<%=total.ClientID%>').val(pos);

Hope this helps.

regards.

Upvotes: 1

Cystack
Cystack

Reputation: 3551

Are you even sure that your input exists ? The tag is not well formed, you have a space between < and input. And the correct command is getElementById, not ID.

Your javascript is correct, this put aside.

Upvotes: 0

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21366

Try this,

$('#total').val(pos);

and check whether your onChange function is called by putting an alert inside the function.

change your function like thi,

$(document).ready(function(){

//your code here...
});

instead of window.addEvent('domready', function()

Upvotes: 1

akhilless
akhilless

Reputation: 3219

why do not you use

$('#total').val(pos);

It should do the trick

Upvotes: 0

Related Questions