...

View Full Version : javascrpit textbox value link



neo97
12-07-2010, 08:47 AM
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:
http://0o.8415.2.img98.com/out.php/i543815_code.jpg

please help me...:confused:

abduraooft
12-07-2010, 08:56 AM
<input name="Textboxfield" type="text" value="">

onclick="location.href=this.form.elements['Textboxfield'].value+'.jpg'"
What if the user enters a file that's not preset in that directory?

Philip M
12-07-2010, 08:58 AM
<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.

neo97
12-07-2010, 09:14 AM
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?

Philip M
12-07-2010, 09:19 AM
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.


<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- 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.

neo97
12-07-2010, 09:24 AM
<input name="Textboxfield" type="text" value="">

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?

Philip M
12-07-2010, 09:32 AM
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.

neo97
12-07-2010, 09:33 AM
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.


<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?

neo97
12-07-2010, 09:40 AM
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

Philip M
12-07-2010, 10:29 AM
Well, the regex for 6 digits and nothing else is


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.

neo97
12-08-2010, 07:16 AM
Well, the regex for 6 digits and nothing else is


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 :thumbsup:

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum