onClick Event dont function well when a certain space is existed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ceejee
    New Member
    • May 2007
    • 5

    onClick Event dont function well when a certain space is existed

    hello there! i had spent lots of time searching and thinking what is the reason why in onClick event like the one below, when a certain space between words is existed, it doesnt function well. can anybody know here the reason. or is there something wrong with my coding. kindly enlighten me if you have some information.

    sample 1(just a simple alert message display)
    <input type = 'button' Name = 'test1' value='CLICK ME'
    onclick = alert('this is only a test')

    sample 2(data set on the elements will be call in the function, but it doesnt work since a certain space is existed on the data)
    <input type='radio' name='jobvalue' value='" & strInputData & "'" & strWork & " onclick=SelValu eJob('" & strInputData & "','" & strInputData2 & "','" & strJOB_ID & "');>"
  • danp129
    Recognized Expert Contributor
    • Jul 2006
    • 323

    #2
    Originally posted by ceejee
    hello there! i had spent lots of time searching and thinking what is the reason why in onClick event like the one below, when a certain space between words is existed, it doesnt function well. can anybody know here the reason. or is there something wrong with my coding. kindly enlighten me if you have some information.

    sample 1(just a simple alert message display)
    <input type = 'button' Name = 'test1' value='CLICK ME'
    onclick = alert('this is only a test')

    sample 2(data set on the elements will be call in the function, but it doesnt work since a certain space is existed on the data)
    <input type='radio' name='jobvalue' value='" & strInputData & "'" & strWork & " onclick=SelValu eJob('" & strInputData & "','" & strInputData2 & "','" & strJOB_ID & "');>"
    Your onclick events are not quoted.
    use
    onclick = "alert('thi s is only a test')"
    instead of
    onclick = alert('this is only a test')

    Comment

    • ceejee
      New Member
      • May 2007
      • 5

      #3
      i also noticed that when i find some format of writing it in other homepage. thanks for your reply. i just have only a question, why is it even if you dont put a double quotation on it but make sure that there is no space present on the data like the one below work? what explanation can you have about it, their difference for example. i just keep on answering my boss that, that is the format on writing it. any reason you have?

      onclick = alert('YAHOOOO' )

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        that's a very interesting thing ;) thanks for that question. i had a look over it and discovered the following:

        when you do:

        [HTML]<body onclick="alert( 't est')">
        dagshgdjhga
        </body>[/HTML]

        erverything is fine ... you set an attribute called 'onclick' and assign a value "alert('t est')".

        when you do:

        [HTML]<body onclick=alert(' t est')>
        dagshgdjhga
        </body>[/HTML]

        the parser assumes that you set the attribute called 'onclick' and assign a value
        of "alert('t" to it ... and 'est' is parsed as a new attribute. this is why you always should assign attribute-values with quotes!!

        you may test my thoughts with mozillas dom-inspector or firefox firebug ;)

        kind regards

        Comment

        • ceejee
          New Member
          • May 2007
          • 5

          #5
          thank you for your reply. it enlight me now. i think its better to follow the W3C rules in setting values to any attributes in html. it should be enclose in double quotation always to avoid this kind or trouble.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            hi ...

            yes of course ... that it what standards are made for ;) ... in case you have more questions post in the forum and we will help you as good as we can ;)

            kind regards

            Comment

            Working...