SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem when comparing strings containing "&"

    hi.
    i am using javascript to compare two strings. it works well with normal strings. but when the strings contain "&" (e.g. & #1234 ; ), it does not work well.

    code:
    q = document.getElementById("q").value;
    a = document.getElementById("a").value;
    if (q == a)
    document.formName.all("check").innerText = "correct";
    else
    document.formName.all("check").innerText = "wrong";


    anyone have any idea to solve this problem.. thanks.

  2. #2
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry. something to add on.
    i am comparing input text value with input hidden value.

    <input type="text" id="q" name="q" value="" />
    <input type="hidden" id="a" name="a" value="& #1234;" /> (no space in between)

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) What html escape sequence is & #1234?

    2) Why would you use an html escape sequence for a hidden form field value, i.e something that won't be displayed in html?

    This is what js is seeing:
    Code:
    <html>
    <head><title></title>
    <script type="text/javascript" language="javascript">
    <!-- Hide from browsers without javascript
    
    window.onload=function()
    {
    	alert(document.getElementById("a").value);
    };
    
    // End hiding -->
    </script>
    </head>
    <body>
    
    <form name="f" method="post" action="">
    
     <input type="hidden" id="a" name="a" value="& #1234;" />
    
    </form>
    
    </body>
    </html>
    Last edited by 7stud; Nov 28, 2005 at 02:18.


Bookmarks

Posting Permissions

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