www.webdeveloper.com
Results 1 to 5 of 5

Thread: How is a page in the src of img got triggered?

  1. #1
    Join Date
    Feb 2011
    Posts
    78

    How is a page in the src of img got triggered?

    Hi there,

    Do you expect "/Consumer/CValidateCode.ashx" in the below <img> src bring a picture to show?
    Code:
    <li>Gotcha:<input id="txtCCPwd" class="edtText" type="text" 
    style="width:70px;" maxlength="4">
    <img class="Validate_Img" title="Click to refresh!" 
    onclick="javascript:this.src='/Consumer/CValidateCode.ashx?' + Math.random();" 
    src="/Consumer/CValidateCode.ashx">
    </li>
    But how below doesn't show the picture? What's wrong? This is about getting a picture from server for gotcha purpose.
    Code:
    <div class="table-td">
    <input id="login-valid" class="login-Text2" type="text" maxlength="4">
    <img class="login-CodeImg" 
    onclick="javascript:this.src='/id/verifycode.php?'+Math.random();" 
    alt="Click to refresh" src="/id/verifycode.php?0.3315922001265288">
    </div>
    Thanks,

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Remove the javascript: part in the onclick attribute.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  3. #3
    Join Date
    Feb 2011
    Posts
    78
    Thanks, ReFreezed.

    The one that doesn't work is 'src="/id/verifycode.php?0.3315922001265288"', not the onclick. The onclick works fine. Please look at http://code.google.com/p/cool-php-captcha/. There similiar code below works perfect: you see '<img src="captcha.php" id="captcha" />' in below code, it gets the picture for <img>. But how in my code, 'src="/id/verifycode.php?0.3315922001265288"' doesn't get the picture.
    Code:
    <form method="GET">
      <img src="captcha.php" id="captcha" /><br/>
      <!-- CHANGE TEXT LINK -->
      <a href="#" onclick="
        document.getElementById('captcha').src='captcha.php?'+Math.random();
        document.getElementById('captcha-form').focus();"
        id="change-image">Not readable? Change text.</a><br/><br/>
      <input type="text" name="captcha" id="captcha-form" autocomplete="off" /><br/>
      <input type="submit" />
    </form>
    Thanks,

  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    So no image shows up when the page loads, but an image does show up when you click? Then maybe you should echo a random number in the initial URL?

    src="/id/verifycode.php?<?php echo rand(); ?>"

    Also, does the same problem occur in all browsers?

    Edit: wait, are you using PHP or ASP.NET on the server?
    Last edited by ReFreezed; 02-04-2013 at 04:02 PM.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  5. #5
    Join Date
    Feb 2011
    Posts
    78
    Thanks again, ReFreezed, for your help. When you click, the content of the src is changed accordingly, but, the picture is not shown. So the click works, but not the picture. The number at the end of url is a random number generated.

    When "http://localhots/id/verifycode.php?0.3315922001265288" is typed in to the address of a browser, an image's name is shown.

    Why the picture is not shown?

    Can any one tell what the sever resopnses with 'captcha.php?'+Math.random(); in below code? A file name for a picture, or the picture is itself? If it's picture itself, how?

    Code:
      <img src="captcha.php" id="captcha" /><br/>
      <!-- CHANGE TEXT LINK -->
      <a href="#" onclick="
        document.getElementById('captcha').src='captcha.php?'+Math.random();
        document.getElementById('captcha-form').focus();"
        id="change-image">Not readable? Change text.</a><br/><br/>
      <input type="text" name="captcha" id="captcha-form" autocomplete="off" /><br/>
      <input type="submit" />
    </form>
    Thanks,
    Last edited by wow; 02-11-2013 at 02:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles