Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    javascrpit textbox value link

    hi guys

    i want to create a input textbox with value link and with help from this forum i have a code like this:

    <form>
    <input name="Textboxfield" type="text" value=".jpg"><br>
    <input name="Launchlink" type="button" value="Launch link" onclick="location.href=this.form.elements['Textboxfield'].value">
    </form>

    this is a good code for me but have some problems.
    in this code the value ".jpg" is variable but i wants to keep it stable who when user insert his/her number in textbox, can go to destination link.

    for example:

    i insert my number 22456 in this textbox like this: 22456.jpg
    and when i press botton the page directly go to my file (a pic).
    but
    when i insert my number without .jpg format the page goes wrong and break the system (show index page)

    and thats my problem! how can i have stable value link ".JPG" who when user jus isert his/her number to textbox the page directlty go to his/her file and show it.

    also you can see this image:


    please help me...

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <input name="Textboxfield" type="text" value="">
    Code:
    onclick="location.href=this.form.elements['Textboxfield'].value+'.jpg'"
    What if the user enters a file that's not preset in that directory?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Code:
    <form> 
    <input name="Textboxfield" type="text" value=""><br> 
    <input name="Launchlink" type="button" value="Launch link" onclick="getLink()">
    </form> 
    
    <script type = "text/javascript">
    function getLink() {
    var x = document.forms[0].Textboxfield.value;
    // check using a regex that value entered is a number within a valid range??  Do you really have 22456 images?
    x = x + ".jpg";
    window.location.href = x;
    }
    </script>

    Mohommad Yousuf shares a birthday with Sir Don Bradman, and a beard with W.G.Grace. - Cricket commentator.
    Last edited by Philip M; 12-07-2010 at 09:11 AM.

  • Users who have thanked Philip M for this post:

    neo97 (12-08-2010)

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    YES its worked!
    this is so good and really thank you guys.
    (but i dont know why JUST you should click on the botton to see results and if you press enter on keyboard code goes worng! you know why?)
    and now i have 2 more questions:

    1- can i use a jquery system for some nice syles in this system?
    for example a code with jquery who after user isert his/her number in textbox show the file in new window in parent window like fade in or a nice load? (dont send the page)

    2- can i use some CAPTCHA system for more security risks?
    for example user insert both his/her number in textbox with a security code another textbox (captcha system) to see file?
    Last edited by neo97; 12-07-2010 at 09:17 AM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by neo97 View Post
    but i dont know why JUST you should click on the botton to see results and if you press enter on keyboard code goes worng! you know why?)
    Because pressing enter causes the form to submit (to itself if no other action is specified). You can overcome this by removing the textbox from the form and using an id rather than form name.

    Code:
    <input id ="Textboxfield" type="text" value=""><br> 
    <input name="Launchlink" type="button" value="Launch link" onclick="getLink()">
    
    <script type = "text/javascript">
    function getLink() {
    var x = document.getElementById("Textboxfield").value;
    // check using a regex that value entered is number within a valid range??
    x = x + ".jpg";
    window.location.href= x;
    }
    </script>


    Quote Originally Posted by neo97 View Post

    1- can i use a jquery system for some nice syles in this system?
    for example a code with jquery who after user isert his/her number in textbox show the file in new window in parent window like fade in or a nice load? (dont send the page)

    2- can i use some CAPTCHA system for more security risks?
    for example user insert both his/her number in textbox with a security code another textbox (captcha system) to see file?
    1) You do not need jQuery to do that.

    2) Yes, of course you can use a captcha but what is the point unless you want to stop bots accessing your images? Naturally a captcha requires server-side scripting. As of course does any kind of password check to allow authorised users only.
    Last edited by Philip M; 12-07-2010 at 09:27 AM.

  • Users who have thanked Philip M for this post:

    neo97 (12-08-2010)

  • #6
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Code:
    <input name="Textboxfield" type="text" value="">
    Code:
    onclick="location.href=this.form.elements['Textboxfield'].value+'.jpg'"
    What if the user enters a file that's not preset in that directory?
    i dont know my friend?
    without any error, page turn back to index and show nothing!
    can i give some error message to system who if user input wrong number after that the system show a error for him?

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by neo97 View Post
    can i give some error message to system who if user input wrong number after that the system show a error for him?
    If you tell us which numbers or range of numbers are valid, then we can help you. The need for validation is why I proposed a separate function.

  • Users who have thanked Philip M for this post:

    neo97 (12-08-2010)

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Because pressing enter causes the form to submit (to itself if no other action is specified). You can overcome this by removing the textbox from the form and using an id rather than form name.

    Code:
    <input id ="Textboxfield" type="text" value=""><br> 
    <input name="Launchlink" type="button" value="Launch link" onclick="getLink()">
    
    <script type = "text/javascript">
    function getLink() {
    var x = document.getElementById("Textboxfield").value;
    // check using a regex that value entered is number within a valid range??
    x = x + ".jpg";
    window.location.href= x;
    }
    </script>




    1) You do not need jQuery to do that.

    2) Yes, of course you can use a captcha but what is the point unless you want to stop bots accessing your images? Naturally a captcha requires server-side scripting. As of course does any kind of password check to allow authorised users only.
    1- well how i can do that?
    for example a nice fade in load in parent window to show the file for user who user can save his/her picture file?

    2- ok i think dont need any more to CAPTCHA system and thanks for your help.
    but what about error message? how can i use error message if user insert wrong number? and how i can use only NUMBERS in textbox who user cant write any wrong words?

  • #9
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    you know, this is ALL OF SYSTEM:

    there are 3000 personal ID cards as pictures who i want to show them for USERS.
    so the ID cards names (or jpeg pictures) are 6 number lenth. numbers are full random and i want to user just insert his/her personal number in textbox and see that personal ID file. this is mean user JUST can input NUMBERS in text box and no any words or characters.
    this is just it dude

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Well, the regex for 6 digits and nothing else is

    Code:
    if(!/^\d{6}$/.test(x)) {
    alert ("You must enter a 6-digit number");
    return false;
    }
    but (a) I could just guess a number repeatedly until I hit on a valid one
    (b) if that .jpg does not exist then an error occurs.

    The whole idea is flawed. You should require each user to enter both his name and his user number, then validate these as corresponding server-side using a database, before anything else happens.

  • Users who have thanked Philip M for this post:

    neo97 (12-08-2010)

  • #11
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Well, the regex for 6 digits and nothing else is

    Code:
    if(!/^\d{6}$/.test(x)) {
    alert ("You must enter a 6-digit number");
    return false;
    }
    but (a) I could just guess a number repeatedly until I hit on a valid one
    (b) if that .jpg does not exist then an error occurs.

    The whole idea is flawed. You should require each user to enter both his name and his user number, then validate these as corresponding server-side using a database, before anything else happens.
    thanks for new code

    yeah dude i know the whole idea is flawed. in the begining i desined a full username & password system based on mysql database (php) but for 3000 ID cards who a person just want view or save it one time and after 15 days all of them will be removed from server, thats not fair (thats heavy).
    now with your helps every thing is ok to me and i like new idea. THANK YOU TOO MUCH

    just one more thing?
    how about my idea for a good effect to load cards? for example how can i load them in a nice and soft effect like fade in parent windows (like some jquery scripts) on this simple system?
    if you can please help me about this one too
    good luck dude


  •  

    Posting Permissions

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