1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Rep Power

    Question <script> document.write button doesn't show, but <noscript> button does?

    Hi all,

    I'm running into two issues with this code:

    <form action="https://somesite.net">
    <input type="hidden" name="var1" value="val1">
    <textarea name='txtArea1"></textarea>
    <script type="text/javascript">	
    document.write('<input type='button' value='Send Message Script' onClick='window.open('https://somesite.net','Windows','width=650,height=350,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');return false'>');
    <noscript><input type="submit" value="Send Message NO Script"></noscript>
    Note: The button "values" are just for testing purposes right now.

    1. I'm trying to get two different submit buttons to show up, independently, depending upon <script> and <noscript>. Mainly, I want the new window opened as described, but of course want to provide an alternative for users without javascript on and thus the need (I think) for the document.write version within the <script> tags.

    Using I.E. 9, when I turn off javascript, I can see the "Send NO Script" button.

    When I turn javascript on, I do not see the "Send Message Script" button. I've tried the script code with and without the <!-- --> declarations. Same result. The button doesn't show.

    Ideas why?


    2. When I click the "Send Message NO Script" button (when js is turned off), the form does submit to the url indicated, however, the inputs on the form show up in the URI portion, hidden field as well as the textarea.

    Why would that occur?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power
    Before I answer: Please leave this thread open and don't close it in the middle of the discussion like always. No idea why you do this and why you ignored my requests, but please don't do it this time, OK?

    The code cannot work, because it's not even syntactically valid. If you paste this into a decent editor or check the JavaScript console of your browser or simply take a close look, you should see what's wrong with this line:

    javascript Code:
    document.write('<input type='button' value='Send Message Script' onClick='window.open('https://somesite.net','Windows','width=650,height=350,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,loc  ation=no,directories=no,status=no');return false'>');

    You randomly open and close the single quotes. How is the poor JavaScript parser supposed to know where the string starts and where it ends?

    I strongly suggest that you use a good editor like Notepad++ or an IDE like Netbeans. It will help you avoid syntax errors.

    The next problem is that document.write() has issues. Do not use it unless you absolutely truly know what you're doing. Changing the HTML document with JavaScript is done by selecting an element and using one of the DOM manipulations methods (like appendChild() or insertBefore() or whatever).

    In your case, you don't need all that. Simply make one submit button and change its functionality with JavaScript. If the user has turned JavaScript off, it will be a simple submit button. If JavaScript is turned on, the button will trigger some JavaScript action.

    The next problem is that unaskedly opening windows is considered bad practice. This may have been OK in the 90s, but nowadays, many browser won't even allow it due to heavy absuse. The user decides how they want to view your page (in a new window, in a new tab or in the same tab). It's none of your business.

    So I suggest you think this through again and come up with a smarter and more user-friendly approach. If you tell us what you wanna do, we can help you with that.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Rep Power
    Thanks for the reply, as always.

    That's what I get for trying to do too many things simultaneously. Can't believe I forgot the method type in the form tag. Good thing I'm doing this in a dev environment eh?

    And yes, now that I've read your post and thought about it, only one button is necessary in this case, so I've made the changes.

    As for
    The user decides how they want to view your page (in a new window, in a new tab or in the same tab). It's none of your business.
    this is an interesting comment.

    I suppose, it's indicative of a new, younger generation's attitude.

    However, in my case, it is my business. Figuratively, and literally. I need to control a certain number of user experiences. Opening a message in a small window and keeping the user on the original page isn't a show stopper for most. This type of thing is found on many very popular "mainstream" web sites out there. I mean, in many cases, they don't even give you and option javascript/no javascript. You don't have js turned on, you can't use that entire portion (or all of) their site. Not everything is a do as you (the user) please situation. So yes, in some cases it is the website builder's/owner's/FI's business to control some aspects of the UI.

    As for closing the thread, I generally do that 1) After I've acknowledged that I've found the answer/accepted the suggestion posted in the thread and 2) Since my OP has been answered, I close the thread so as to not leave it open indefinitely which a) may indicate to some an unresolved thread and b) folks don't ask me/tell me "why don't you close the thread when your done?"

    But I digress. Again, thanks for the input.

IMN logo majestic logo threadwatch logo seochat tools logo