Results 1 to 3 of 3

Thread: Avoid quotes in onclick?

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Avoid quotes in onclick?

    Need to avoid the quotes around the onclick action in my html code to to php. is this possible?

    Current call
    Code:
       <input type="button" value="Steg 1" onclick="show('QA')"/>
    Want it to be
    Code:
       <input type="button" value="Steg 1" onclick="show(QA)"/>
    My javascript
    Code:
     function show(id) {
    	
    	
           var e = document.getElementById(id);
           if(e.style.display == 'block')
              e.style.display = 'none';
           else
              e.style.display = 'block';
        }
    Possible?

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    If and only if a variable QA is defined somewere in let's say a script tag defined before the element in question. Basically, that would create more trouble than it's worth. Try using \" instead of '
    Trinithis

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can do:
    Code:
    <input type="button" value="Steg 1" onclick="show(&quot;QA&quot;)">
    but this is very ugly. The fact that you need to do this is generally indicative of poor coding practices in the PHP. Break out of PHP parsing mode to output HTML, or even better, use a dedicated template system like Smarty.

    Also read http://www.webdevout.net/articles/beware-of-xhtml and http://www.hixie.ch/advocacy/xhtml for reasons not to use XHTML at the present.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •