Getting JavaScript error: "Cannot assign to '[string]'"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • preeti13
    New Member
    • Aug 2007
    • 67

    Getting JavaScript error: "Cannot assign to '[string]'"

    i have a java script function with the pop up i want to update a database ow i am getting the erorr any one please help me with this.

    code is like this
    [CODE=javascript]

    <script type="text/javascript">
    function disp_confirm(em ployeenominatio nid)
    {


    var r=confirm('Are you sure ?:'+employeenom inationid)
    if (r==true)
    {
    window.location = 'Winner.aspx?Em pNomId='++;empl oyeenominationi d;

    document.Form1. submit()
    }
    else
    {

    //document.write( "You pressed Cancel!")
    }
    }

    </script>
    [/CODE]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Preeti.

    Here's where your problem lies:
    [code=javascript]
    'Winner.aspx?Em pNomId='++;
    [/code]

    This code attempts to increment the value of 'Winner.aspx?Em pNomId=' by 1 and then save then new value to itself, which is just wrong on so many levels.

    P.S., Changed thread title to better describe the problem (did you know that thread titles that do not follow the Posting Guidelines actually get FEWER responses?).

    Comment

    • preeti13
      New Member
      • Aug 2007
      • 67

      #3
      thanks for replying .but i need that id because based on that id i am try to update the database do i need a server side code for that please help me i feel really stuck in there

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Preeti.

        The problem is not the 'Winner.aspx?Em pNomId=' part. The problem is the '++;' part.

        Did you mean this instead:
        [code=javascript]
        window.location = 'Winner.aspx?Em pNomId=' + employeenominat ionid;
        [/code]

        Comment

        • preeti13
          New Member
          • Aug 2007
          • 67

          #5
          thanks for helping me out but now i want that id in the url how i can get that id in the url please tell

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Preeti.

            To put the id in the URL, you'd simply do this:
            [code=javascript]
            window.location = 'Winner.aspx?Em pNomId=' + employeenominat ionid;
            [/code]

            Which is different from what you were trying to do previously:
            [code=javascript]
            window.location = 'Winner.aspx?Em pNomId='++;empl oyeenominationi d;
            [/code]

            Comment

            • preeti13
              New Member
              • Aug 2007
              • 67

              #7
              yes sir as you said i made a change in the code my code is now look like this
              Code:
              <script type="text/javascript">
               function disp_confirm(employeenominationid)
                {
              
                
                var r=confirm('Are you sure ?:'+employeenominationid)
                 if (r==true)
                  {
                
              window.location ='Winner.aspx?EmpNomId=' + employeenominationid;
               document.Form1.submit()
                    }
                else
                  {
                
                  //document.write("You pressed Cancel!")
                  }
                }
                
              		</script>
              and server side code i am call a qurey string like this

              Code:
              
              			string EomNomid;
              			EomNomid = Request.QueryString["employeenominationid"];

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, Preeti.

                Close.

                Your server-side code doesn't talk with JavaScript that way, so instead of using the name of the JavaScript variable, you need to use the name that you put in the URL:

                [code=asp]
                string EomNomid;
                EomNomid = Request.QuerySt ring["EmpNomId"];
                [/code]

                Comment

                Working...