Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: u won't call it a problem ..

  1. #1
    Join Date
    Oct 2005
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile u won't call it a problem ..

    hi all,
    at first ,, i dont speak english ,, and i don't think that it's a problem
    and my english is weak ..

    ........ :
    i have a small problem ..
    the problem is ....................
    hmm i think u'll understand by the code below ..
    Code:
    <script>
    var mmm = Math.round(Math.random()*27);
    var ar = new Array("2", "3", "5", "7", "8", "20", "24", "25", "15", "16", 
    "17", "18", "10", "13", "26", "28", "30", "31", "36", "37", "39", "40", "41", "42", 
    "44", "46", "50", "51");
    document.write(ar[mmm]);
    </script>
    this script works 100% .. as u see ..
    when u refresh the page u will get a new number from the array ..ok ?

    but when we write this :
    Code:
    <form name="dynamicdrive">
    <input type="text" name="num"></form>
    <script>
    var mmm = Math.round(Math.random()*27);
    var ar = new Array("2", "3", "5", "7", "8", "20", "24", "25", "15", "16", 
    "17", "18", "10", "13", "26", "28", "30", "31", "36", "37", "39", "40", "41", "42", 
    "44", "46", "50", "51");
    document.dynamicdrive.num.value = ar[mmm];
    </script>
    it gives a fixed number ..
    i don't know whyyy ?????
    someone helps me ?
    ((( i wrote the code in the simplest way just to let u understand it )))
    ....
    &&&Black Label&&&

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following code

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Untitled Document</title>
    		<style type="text/css">
    
    		</style>
    		<script type="text/javascript">
    			var mmm = Math.round(Math.random()*27);
    			var ar = new Array("2", "3", "5", "7", "8", "20", "24", "25", "15", "16", "17", "18", "10", "13", "26", "28", "30", "31", "36", "37", "39", "40", "41", "42", "44", "46", "50", "51");
    			window.onload = function() {
    				document.dynamicdrive.num.value = ar[mmm];
    			}			
    		</script>
    	</head>
    	<body>
    		<form name="dynamicdrive">
    			<input type="text" name="num" /></form>
    	</body>
    </html>
    Last edited by codeexploiter; 07-03-2007 at 10:12 AM. Reason: Correction in code

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    />
    That's for XHTML.
    HTML =
    Code:
    >
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I forgot to insert the closing tag, mistake from my part and thanks for pointing that man

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

    Default

    That wasn't the point tech_support was trying to make. You've used an HTML DOCTYPE and even declared Content-Type: text/html using <meta> elements, but at several places in your code you've used XML-style ending tags, such as
    Code:
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    These are invalid in HTML.*

    * well, technically they're valid, although they have a vastly different meaning from that they possess in HTML, but no browser today implements the NET feature of SGML that these require to work.
    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!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The script as written should work, and does in Opera and FF, just not in IE. Using the defer attribute in the script tag, like so:

    Code:
    <form action="#" name="dynamicdrive">
    <input type="text" name="num">
    </form>
    <script type="text/javascript" defer>
    var mmm = Math.round(Math.random()*27);
    var ar = new Array("2", "3", "5", "7", "8", "20", "24", "25", "15", "16", 
    "17", "18", "10", "13", "26", "28", "30", "31", "36", "37", "39", "40", "41", "42", 
    "44", "46", "50", "51");
    document.dynamicdrive.num.value = ar[mmm];
    </script>
    makes it work in IE as well. This really seems to me like a bug in IE though.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What is "defer"?
    (I could look it up, but I'm assuming it might help others too.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    I think it makes the script load when the page is loaded.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Load after the page has loaded?
    reload each time the page loads?
    something else?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    W3Schools:

    defer - Indicates that the script is not going to generate any document content. The browser can continue parsing and drawing the page.

    W3C:

    defer - When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.

    So, basically it is telling the browser that it can continue drawing the page. However, this should be immaterial in this case, and is in Opera and FF, as all the browser needs to execute the script has already been parsed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •