0

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 + ' %');
    });
1
  • 2
    Try document.getElementById instead of document.getElementByID Commented Oct 14, 2011 at 8:19

5 Answers 5

2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ravi! this work perfect! finally.. document.forms["form1"]["total"].value = pos; =)
1

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()

2 Comments

thanks for the quick response. unfortunately, the code you mention didn't pass anything to the inputbox (total). i did also get an error when inspecting the element. "uncaught Typerror; Cannot call method 'val' of null" =(
check my answer, I think your input doesn't even exist
1

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.

2 Comments

Thanks for your suggestion, but when i tried the first and second code both didnt pass anything, also noticed the error when i inspected the element of the page "Uncaught Typerror; Object #<HTMLDocument> has no method 'getElementByID'" and "uncaught Typerror; Cannot call method 'val' of null".. TIA!
As "Cystack" mentioned, "getElementByID" does not exist. is "getElementById".
0

why do not you use

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

It should do the trick

1 Comment

i already tried that but i didnt pass anything. also got an error when inpecting the element on the page. "uncaught Typerror; Cannot call method 'val' of null".
0

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.

1 Comment

yes my input exists. here's the code "<input type="hidden" id="total" value="" style="border:0; color:#f6931f; font-weight:bold;" runat="server" />". I did edited the tag getElementById. i just mistyped it when posting the question. will try it again. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.