Results 1 to 2 of 2

Thread: [RESOLVED] Textbox, Radio controls, and label/Span values clearing after JavaScript function

  1. #1

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243

    Resolved [RESOLVED] Textbox, Radio controls, and label/Span values clearing after JavaScript function

    I am trying to pass back a value into a label/span using the document.getElementById method in an ASPX file.
    It clears all the values in the form (option labels, textbox, and label/span). I do not want this obviously.
    I made sure that the button is not an asp:button to prevent the postback keep it all client side driven.

    What do I need to do to prevent the form from resetting?
    Why does the document.getElementById("lblInchToMM").innerHTML not seem to work unless I use "ctl00_ContentPlaceHolder2_lblInchToMM"?

    I have tried to use EnableViewState in both true and false values, and ClientIDMode = static to try and fix it.

    HTML:

    HTML Code:
    <input id="radioInch" type="radio" name="rdoInchMM" value="Inch" title="Inches" />Inches to Millimeters<br />
    <input id="radioMM" type="radio" name="rdoInchMM" value="MM" title="MM"/>Millimeters to Inches<br />
    <input id="txtInchToMM" type="text" />
    <input id="btnInchToMM" type="submit" value="submit" onclick="PassBackValue();" /><br />
    <asp:Label ID="lblInchToMM" EnableViewState="false" ClientIDMode="Static" runat="server" Text="result"></asp:Label>

    JavaScript that doesn't seem to work using "lblInchToMM":
    Code:
    function PassBackValue() {
            var sngValue = document.getElementById("txtInchToMM").value;
            document.getElementById("lblInchToMM").innerHTML = "From js " + sngValue;
    
        }
    JavaScript that seems to work except it clears the textbox value and I can see the label/span lblInchToMM flash the value then reset to the default of "result":
    Code:
    function PassBackValue() {
            var sngValue = document.getElementById("txtInchToMM").value;
            document.getElementById("ctl00_ContentPlaceHolder2_lblInchToMM").innerHTML = "From js " + sngValue;
    
        }
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  2. #2

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243

    Re: Textbox, Radio controls, and label/Span values clearing after JavaScript function

    Ok... for anyone having this same problem, it is due to the controls being nested within a form which would submit to a server....
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width